Dropdown Listbox In Subroute - How To Pass Cell Argument
Dec 19, 2013
I am coding a spreadsheet that makes extensive use of the excel dropdown list boxes. So I have codes such all over and it is not a neat way to code.
Code:
With Target.Validation
.Delete
.Add xlValidateList, 1, 1, Formula1:="1, 2, 3"
.InCellDropdown = True
.ShowInput = True
End With
As many of the dropdown list boxes are similar in nature, with the only exception that the list content is different, I wanted to code a sub routine to include the code above.
My subroutine looks like this now:
Code:
Sub listbox(cellref As Range)
Set Target = Cells(cellref)
With Target.Validation
.Delete
.Add xlValidateList, 1, 1, Formula1:="1, 2, 3"
.InCellDropdown = True
.ShowInput = True
End With
End Sub
The problem is that when I call the subroutine with a
Call listbox (10,10)
It kept giving me a compile error.
I would like to create a listbox at cell row 10, column 10 of the worksheet.
The second subroutine below selects a range of cells, in this case a column. It selects a range that ends with the last cell that has data and starts with either the first cell that has data or the second cell has data (needed for instance if the first cell is just the heading and doesn't contain data). You'll notice I have hardcoded the "includeFirst" option right now. I don't know how to pass this as an argument when calling this subroutine.
In the first subroutine updateAll() I need to call the second subroutine and want to pass an argument to it. Maybe my approach using subs and application.run is the wrong way to do this?
Sub updateAll() includeHeader = False Application.Run "SelectColumn" ' need something like: ' Application.Run "SelectColumn(includeHeader)" ' where subroutine below has something like: ' Sub SelectColumn(includeFirst) End Sub
Sub SelectColumn() 'Select a Column or Row of Cells in a Used Range Quickly 'http://msdn2.microsoft.com/En-US/library/aa155432(office.10).aspx includeFirst = False 'includeFirst = True Dim UpBound As Range Dim LowBound As Range If ActiveCell.Row > 1 Then If IsEmpty(ActiveCell.Offset(-1, 0)) Then Set UpBound = ActiveCell........................
I use the code below to enter a value from a list box in a cell on a workssheet. Is it possible to code VBA to enter a number for the position of the selection in the listbox to a cell in a worksheet rather that the actual value from the list box. For example if my list is:
Option1 Option2 Option3
And I click on Option2 in the list, I can sennd the value 2 to a cell on the worksheet rather that the value "Option2' from the list.
Private Sub ListBox1_Click() Sheets("SA").Range("SA_Poistion_To_Archive_A_New").Value = ListBox1 End Sub
I have this data inputted into excel sheet: [URL] .......
This data is in tab called Shops, that has 8 columns of information. In another sheet called control, I have the shops names from row A in a list box. What I am trying to do is when whatever shop is selected in the list box then output the shop information from that row in 8 different cells in another sheet. I have a list of about 200 shops that I need to input.
So if we pick shop, Abc inc from the list box how can I get excel to look up the information in Abc inc in the shops tab of information and then display them on other cells in different sheets.
I have the same issue with making a list box of people names. I made the list box but I want to make it so it will display there phone number and e-mail address in 2 other cells once you pick there names. I had some luck using the if command on smaller list boxes but I can't figure out how to get multiple cells of information to come out correctly
I know you can read a range of data into a ListBox with a single command. can you read the contents of a ListBox into an array with a single line, and if so what is the syntax?
I am going to use excel for test cases. I can creat a drop down list with the selections "pass", "fail", "not run". That isn't a problem using the data validation toolbar. However I would like to basically color the cell (test case) with a certain color based on the drop down selection.
I have a list of 150 names and I am looking for the best options to select between those. I will generally type part of the name and expect for the closest match to appear.
I have tried listbox userform, it does not work, even though it's locked and formatted not to move, its size changes all the time causing Excel to crash and lost hours of work done on the sheet.
I have tried also a drop down list, but it's very hard to search for names manually.
What other options do I have? I think the best would be some kind of search box but I can't find any in the insert userform tab.
I have a userform where I want the user to be able to select multiple options, but am having a bit of a problem finding the best way to do this. If I use a combobox, I don't appear to be able to allow multiple selections, but if I use a listbox I don't appear to be able to implement a dropdown facility. I would prefer to have a single line sized box on my form, but doing this with a listbox would probably be confusing for the user as it is not very easy to see what has been selected.
I have an attached file and I am trying to build a VBA function to calculate total values. First row is "RollingTime" and for example if I am trying to calculate the "Total" value. For "RollingTime" = 2 it should be
I have some code I wrote that copies sheets from another sheet in another workbook to my current one, in order. However, depending on activity within these sheets, there might not be a sheet for the month.
I have the on error code to go to the next argument, however I would like it to tell me on my errors sheet that it did not exist.
The error sheet will simply have 2 columns of copied sheets and non-existent sheet.
VB: On Error Resume Next Workbooks("GLTemp").Sheets("981715").Copy After:=Workbooks("MHSGMR").Sheets("981715 Budget") Workbooks("MHSGMR").Sheets("981715").Activate sheetName = ActiveSheet.Name Workbooks("MHSGMR").Sheets("981715").Select ActiveSheet.Name = sheetName & " GL"
I wish I could read the name of the file (myfile_12112012.xlsx) or, alternatively, all of the function's first argument (('[myfile_12112012.xlsx]RIEPILOGO'!$C$2:$C$12) from a separate cell.
I tried this:
SOMMA.SE = (C2, E1, '[myfile_12112012.xlsx] ERROR SUMMARY'! $ B $ 2: $ B $ 12)
putting in the cell C2 the string:
'[myfile_12112012.xlsx]RIEPILOGO'!$C$2:$C$12
In this way, however, the formula does not work.
How can I read and evaluate correctly the first argument from the cell c2?
If I have cells that are formatted to a certain decimal width, say, 2 digits, cells that have the value of 3.599 will appear as 3.60. When I reference this cell in VBA, how can I have it pickup the 3.60? Currently, something like Range("A1") or Range("A1").Value will pickup the 3.599.
I feel like theres something thats like Range("A1").XXXX that will get me there, but I can't seem to guess it.
I have workbook template that I use to generate reports from a list of depts. This list is contained in a drop down cell that is a named range in a different worksheet. My current process is as follows:
-Select Dept Name from the list -Click a command button which is assigned to code that calculates and saves to a file -Repeat for next report until all reports are generated
I would like to automate this process by producing all reports with a single command with the following functionality:
-The Dept Name needs to be populated in the specified cell containing the current drop down because it drive various vlookups and other formulas -If possible, I would like to retain the drop down functionality as I would like to have the option of running an individual report or running the “batch”.
I am doing a simple filter list copy and paste into another worksheet and I have a challenge trying to pass the value in Cell B1 (which contains the city) as a filter parameter in the filtered list.
I have the below code which creates a new template
Code: Private Sub NewTemplate_Click() Dim Tsh As Worksheet Set Tsh = Sheets("TEMPLATE") Tsh.Copy After:=Sheets(Sheets.Count) shName = InputBox("Please enter new sheet name:") ActiveSheet.Name = shName Tsh.Visible = False End Sub
What I would like to add to the above code is two more inputbox prompts, the first should prompt the user for a Name (text and length) to go into the new sheet cell A6. The the second input box should as for code, (number any length), to go into the new sheet cell b6.
I have a macro that nicely select the named range that the active cell is in. I want to chain on to that macro a macro that has a parameter a range with that active selection. I dont see how to "take" the active selection on the worksheet from within the macro and pass it to another. I assume I could change the cellInRange macro to return a range, however I dont yet see how to do that.
I want to put some colour in the cells B2, B3, B4, B5, etc and a put black the edge of every box. For do that i make a subrutime that put some color in the range that i want (only if i write "B2" or "B2:B5"), but if i want to put a black edge in all the box i can't do "B2:B5". Then i tried to do something like:
For i=2 To 5 Step 1 Call Boxcute(ActiveSheet.Cells(i,2)) Next i
Sub Boxcute (Box As String) Range(Box).Selection etc. End Sub
I am using this program in one workbook to capture the datevalue in integer from another workbook which i opened. But the program as it reaches the line x2=Datevalue( Cells(2,14).Value) gives a Type Mismatch error.
Public Sub find_date() Dim x2 As Long
'I am trying to activate the last opened file by using workbooks.count Workbooks(Workbooks.Count).Activate Worksheets("Sheet1").Cells(1, 1).Select
x2 = DateValue(Cells(2, 14).Value)
End Sub
Auto Merged Post Until 24 Hrs Passes;btw..the cells(2,14) has a date, formatted in the type of mm/dd/yyyy.
I need to pass range information (eg. WorkSheets("abc").Range("A1") as text or ??) from a cell (ie the above text is in a cell on some worksheet, say "XYZ") to a VBA procedure or could directly use it in the procedure, similar to...
Sub MyProc(RngInfo as string [or?]) dim RRng as range Set RRng= RngInfo ??? it is this part I'm really not sure how to do
where RngInfo is a worksheet that has a "named" cell that contains the above cell with the indicated range in it.
eg. RngInfo is worksheets("XYZ").Range("D1") where D1 contains the text (or ?)WorkSheets("abc").Range("A1")
I've only indicated these as text items because I'm not sure what/how you would do this. The end purpose of this is to pass variable Range information from a cell on a WS either into (or use within directly) a VBA Sub. I guess I could pass the WS and Range Address as a single string separated by a "Char" and use Split to separate them and then recombine using Worksheets(Parm(0)).Range(Parm(1)) but it seems like it should be easier than that.
I am using excel to stop and start a service on the network and have that part done when using a txtfield to enter in the PC ID. What i want to do is use a list of PCIDs and pass them to my service object to stop and start the service.
Private Sub CommandButton1_Click()
Worksheets("PCIDs"). Range("B2").Select 'my issue is here Range("B2").Activate 'and here
Do Until IsEmpty(ActiveCell) Call StopService("ServiceName") ActiveCell.Offset(1, 0).Select Loop
Range("B1").Activate Do Until IsEmpty(ActiveCell) Call StartService("ServiceName") ActiveCell.Offset(1, 0).Select Loop
Worksheets("ServiceName").Select End Sub
and with this function i need it to pass as a string to txtDeviceID. I have tried just simply setting txtDeviceID as ActiveCell but it didn't like that.
Public Function StopService(ServiceName As String) As Boolean
Dim oSysInfo As New ActiveDs.WinNTSystemInfo Dim oComp As ActiveDs.IADsComputer Dim oSvcOp As ActiveDs.IADsServiceOperations Dim sCompName As String Dim sSvc As String Dim lRet As Boolean
I can't use code for this problem as I need to give this to someone who doesn't know VBA. They will need to use it in several different reports, so I can't produce something in VBA very easily. I have three worksheets, Summary, Year1 and Year2.
I want to display either Year1 or Year2 data in the Summary sheet depending on what the user enters in a cell in the Summary sheet. For example, if the user enters "Year1" in cell E2 then I want to point to a cell in the Year1 spreadsheet. I tried using formula: =E2 & "!B3" but this doesn't work. Is there another solution? I have attached an example.
I am trying to create a macro (please look the attached excel what I have done), I have already crwated a macro that after 5 seconds is gonna change the background color of the of the cell en function of another cell.
That means if F3:F4 change the background color F8:is going to change the backgorung color also, every 5 seconds. The macro I wrote is also include in the excel attached file.
Now this is my problem... I have a variable cell that is give for D6 which could be A,B,C,D,E,F (Range F2:K2).
If the variable cell D6 is A the background color of F8:F9 should be the background color F3:F4 .
If the variable cell D6 is B the background color of F8:F9 should be the background color G3:G4 .
If the variable cell D6 is C the background color of F8:F9 should be the background color H3:H4 ......and etcetera.
The above Date si used in a sql select statement where I'm hard coding the date (9/20/2007). This date is actually located in sheet1, cell E1. How can I get it from that cell and use it in my Select statement instead of entering the date manually every day in my code?