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.

View 9 Replies


ADVERTISEMENT

Pass A Named Range From A Cell As An Argument To A Formula

Oct 20, 2009

I have the following formula which works fine in this form:

View 4 Replies View Related

Pass Argument To A Sub From Another Sub

Jul 19, 2007

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........................

View 3 Replies View Related

Pass More Than One Argument To Procedure

Dec 11, 2006

I want to be able to call a procedure and pas 2 variables that it will need to it.
The code looks like this:


Private Sub UpdateScreen(StartLine As Byte, EndLine As Byte)

End Sub
UpdateScreen(104 , 140)

For some odd reason I get an "Expected: = "error when I enter the last line. I works if I send only one variable, but not when I send 2.

View 2 Replies View Related

Pass Chosen ListBox Item Number To Cell

Oct 5, 2007

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

View 2 Replies View Related

Listbox Dropdown Returning Multiple Cell Information

Feb 5, 2014

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

View 1 Replies View Related

Pass Listbox List Into Array

Sep 4, 2007

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?

View 2 Replies View Related

Pass The Contents Of A Listbox To A Function To Sort It Into Alphabeticalorder

Mar 3, 2008

I'm trying to do is pass the contents of a listbox to a function to sort it into alphabeticalorder. I get a error saying object required

Sub PopulateAll()
Dim lgLastRow As Long
Dim lgRowCounter As Long
Dim intCounter As Integer
Dim olb As MSForms.ListBox

For intCounter = 0 To UBound(vAllEnv)
Me.lstAll.AddItem (vAllEnv(intCounter))

Next intCounter

Set olb = frmOptions.lstAll.........................

View 9 Replies View Related

Creating A Dropdown List With Pass/Fail With Colors

Oct 16, 2007

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.

for instance:

Pass = Green
Fail = Red
Not run = Orange.

View 9 Replies View Related

Alternative To Listbox - Dropdown List

Apr 9, 2014

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.

View 6 Replies View Related

Combobox Multiple Selection Or Listbox Dropdown?

Oct 25, 2010

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.

View 11 Replies View Related

Function Argument's Cell Adress

Sep 16, 2009

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

RollingTime(2)*Percentage(2)+RollingTime (1)*(1-Percentage(1))*Percentage(2)+RollingTime(0)*(1-Percentage(0)*(1-Percentage(1))*Percentage(2)

Which is 109732508*0,3 + 1017508995*(1-0,2)*0,3+1587172158*(1-0,1)*(1-0,2)*0,3

And here is the code I have tried to produce:

View 10 Replies View Related

On Error Enter Sheet Name Into Cell Then Next Argument

Jul 31, 2014

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"

[Code] ......

View 3 Replies View Related

Reading Function Argument From Separate Cell?

Dec 3, 2012

I have the following problem: I have this formula, that works correctly:

=SOMMA.SE('[myfile_12112012.xlsx]RIEPILOGO'!$C$2:$C$12;E1;'[myfile_12112012.xlsx]RIEPILOGO'!$B$2:$B$12)

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?

View 2 Replies View Related

Pass Cell Value To VBA & Round It Off

Oct 1, 2006

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.

View 6 Replies View Related

Pass Value: Last Used Cell In Column

Oct 30, 2006

I want to use the value of the last cell as a starting value and add a number to it and assign it to the next cell.
i have this

Sub a()
For i = 15 To 100
Cells(i, 2).Value = Cells(i - 1, 2).Value + 6
Next i
End Sub

how do i incorporate this

Sheets("Sheet1").Range("A").End(xlUp).Offset(0,0).value

into the code above so that the value of the last cell can be the starting value.

View 3 Replies View Related

Pass Each Cell Value In Range To Cell & Run Macro Code

Apr 28, 2008

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”.

View 2 Replies View Related

Pass Cell Content Into A Filter

Jul 22, 2009

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.

View 2 Replies View Related

Input Box To Pass Text To Cell?

Dec 31, 2013

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.

View 3 Replies View Related

Pass Cell Values To VBA Array

Sep 18, 2009

i'm trying to do my homework which requires me to pass values from an array in excel worksheet to VBA and print it in a msg box

i've tried

dim arr as variant
arr = range("A1:A6").value
msgbox arr

but it didn't work.

that's the first step of the homework the second is i have 2 list of array

year:1999 - 2002
profit:10,20,30,40

i have to find the max profit and get the year when it occurs

View 9 Replies View Related

Pass Cell Value Using Variable Row Number

Aug 15, 2008

Following statement works for me:

bdcTerm1 = ThisWorkbook. Sheets("ws2"). Range("A1").Value

But instead I want to parse through 50 rows and dynamically get the value instead of using a static Range("A1"). So I am trying to do the following:


For Row = 1 To bdc_rows
bdcTerm1 = ThisWorkbook.Sheets("ws2").Cell(Row, 1).Value
bdcTerm2 = ThisWorkbook.Sheets("ws2").Cell(Row, 2).Value
Next Row

But I get errror.

View 5 Replies View Related

Pass Cell Variable Between Macros

Jun 11, 2007

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.

View 2 Replies View Related

Pass Cell In Loop To Procedure

Jan 1, 2008

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

But Excel gives me a error with Box and Range.

View 2 Replies View Related

Pass Date In Cell To Variable

Jun 3, 2008

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.

View 4 Replies View Related

Pass Decimal To Variable & Then To Cell

Jun 3, 2008

Why when I want to use a varaible with a value like that 2.1, 0.9, 3.5 in a code to create a formula gives me an error? How to get it work?

Sub Code1()
Dim k As Double
k = 2.1
Range("h11").Formula = "=" & k
End Sub

Strange, but it works well if k is an integer with no Decimal Fraction, like 1, 2, 5, 11 ..

View 4 Replies View Related

Pass WB / WS / Range Info From Cell To VBA Procedure?

May 31, 2013

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.

View 9 Replies View Related

Select Cell & Pass Data To Another Object

Dec 22, 2006

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

View 3 Replies View Related

Change Sheet Name In Cell And Pass Through Formula

Mar 23, 2007

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.

View 6 Replies View Related

Find Row Number Of Cell & Pass To Variable

Aug 4, 2007

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.

View 5 Replies View Related

Pass Date In Cell To Variable & Format

Sep 28, 2007

I'll get straight to the point:

where ( Date > 9/20/2007)

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?

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved