I am trying to create two drop down where the first one will have Years and the second one will have months. If I select year 2015, 2nd dropdown should display only months from Jan to Sep. If I select year 2014, 2nd drop down should display all months. Could any one of you help me to od this in excel?
Try this short macro:
Sub DVSetup()
Range("A1:B1").Clear
With Range("A1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="2014,2015"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
For i = 1 To 12
Range("C" & i).Value = Format(DateSerial(2000, i, 1), "mmm")
Next i
With Range("B1").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=IF(A1=2014,C1:C12,C1:C9)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
It sets up DV in cell A1 to allow a pick between 2014 and 2015. It also sets up DV in cell B1 to allow the correct month range for each year selected in A1 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.