I am trying to create a dynamic drop-down list from column A in a table located in sheet("Historical Data").
This sheet is constantly being updated with new rows added and I would like to have my drop-down list updated automatically.
I have made a dynamic range LastRow = Sheets("Historical Data").Range("A3").End(xlDown).Row
and I am trying to put it in the formula.
Here is the code I have written so far:
LastRow = Sheets("Historical Data").Range("A3").End(xlDown).Row
Worksheets("Chart").Activate
Range("C1").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Historical Data!$A$3:A" & LastRow & ")"
End With
I would like to do another drop-down from the header row. I have made another dynamic range; here is the code, but it does not work (I am pretty new to VBA) :
LastColumn = Sheets("Historical Data").Cells(2, Sheets("Historical Data").Columns.Count).End(xlToLeft).Column
Range("G1").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="='Historical Data'!$T$2:" & LastColumn & "2"
An application-defined or object-defined error appears
Select
andActivate
is bad practise and should be avoided – Tim StackFormula1
argument seems to serve no purpose – Tim Stack