Variable Data Validation Range in a Macro

elotromateo

New Member
Joined
May 19, 2010
Messages
42
I'm trying to add a list to a cell with a macro. I am using a list of cells as the options for the list in the target cell. Unfortunately, this list is going to change in length and I can't figure out how to add a range for this kind of setup. I know the location of the first cell (RowStart), and I can search for the last cell in the macro (RowEnd), but I can't put them in after "Formula1:=". How do I add the range into this?


Code:
Sub UpdateBldgs()


Set RowStart = Worksheets("Update Sheet").Cells(3, 12)
Set RowEnd = Worksheets("Update Sheet").Cells(Range("L" & Rows.Count).End(xlUp).Row, 12)
x = RowStart.Address()
y = RowEnd.Address()

Range("C1").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:= ?
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

elotromateo

New Member
Joined
May 19, 2010
Messages
42
A follow-up of sorts. I figured out that I can cheat and just add the entire column and the list will only show those cells that are not blank. Unfortunately, I also need to do this for a Combo box, but this shows the blank cells, so I can't sneak out of this one. Now I don't know what to put after ".ListFillRange =".

Code:
Sub Macro7()
'
x = Range(Cells(3, 12), Cells(Range("L" & Rows.Count).End(xlUp).Row, 12))

    ActiveSheet.Shapes("Drop Down 7").Select
    With Selection
        .ListFillRange = ?
        .LinkedCell = "$G$6"
        .DropDownLines = 8
        .Display3DShading = False
    End With
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,962
Messages
5,599,065
Members
414,281
Latest member
Engjamal2021

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top