I have one column has comma separated values populating from DB. The Range could be anything.
When open the workbook that comma separated column should be dropdown with values using vba.
I am very new to this macro. I have written the below code. its working fine for single cell. But, I want to do this for certain range like example "H" Column from H1 to last. How to achieve this? Can help me?
Private Sub Workbook_Open()
AddListValidation "Task", "A1", "A2"
End Sub
Sub AddListValidation(sheet, cellSource As Range, cellTarget As Range)
Dim Lastrow As Integer
Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
txt = ActiveWorkbook.Worksheets(sheet).Range(cellSource).Value
ActiveWorkbook.Worksheets(sheet).Range(cellTarget) = "Select your values here"
With ActiveWorkbook.Worksheets(sheet).Range(cellTarget).Validation
.Delete
.Add Type:=xlValidateList, Formula1:="xxx,yyy,zzz"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
split
the values in the first column. It is possible to do so, without vba. I think you may find this post usefull to integrate into your generated code – fictimaph