0
Thanks

A few words of thanks would be greatly appreciated.

Excel - Create drop down list on certain cells



Issue



I wanted to create a drop down list from data in Sheet2. I have tried the following codes but the outcome seems to be incorrect. Instead of the data in Sheet2 listed in the drop down list, the drop down list contained the data from Sheet1 (which is my destination sheet).

Also, I would like to have the drop down list on certain cells where I have information on the cells before, i.e. the drop down list should be in Column F of Sheet1 where there is information on Column E of Sheet1 and repeat until the end of the list.

Herewith attached is the file I am working on here.

Solution


You create a validation list from ANOTHER WORKSHEET give a range name to that validation list(in sheet2)
and use that as the formula

I tried to modify your macro without disturbing except changing one or two lines
I have given range name as "rangename". you can change it in the macro

If necessary tweak it little more.

Sub Dropdown()
Dim x As Long, y As Long
Dim objCell As Range
Dim objDataRangeStart As Range
Dim objDataRangeEnd As Range
Dim rangename As String
' >> Set The Range For Valid Data
Set wsSourceList = Sheets("Sheet2")
Set wsDestList = Sheets("Sheet1")
Set objDataRangeStart = wsSourceList.Cells(1, 2) 'Start range for dropdown list entries
Set objDataRangeEnd = wsSourceList.Cells(6, 2) 'End range for dropdown list entries
MsgBox objDataRangeStart
MsgBox objDataRangeEnd
'=================
With Worksheets("Sheet2")
Range(objDataRangeStart, objdatarangaeend).Name = "rangename"
End With
'=====================
' >> Set Validation On Required Cell
'Set objCell = wsDestList.Cells(8, 4) 'Location of the dropdown list
'MsgBox objCell
x = 4
y = 6

Do
Set objCell = wsDestList.Cells(x, y) 'Location of the dropdown list

With objCell.Validation
  .Delete
  '.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=" & objDataRangeStart.Address & ":" & objDataRangeEnd.Address
  '===========================================
  .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=rangename"
  '================================================================
  .IgnoreBlank = True
  .InCellDropdown = True
  .ErrorTitle = "Warning"
  .ErrorMessage = "Please select a value from the list available in the selected cell."
  .ShowError = True
End With
x = x + 1
'y = y + 1
Loop Until x = 51

End Sub


Thanks to venkat1926 for this tip.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team

Published by . Latest update on by deri58.

This document, titled "Excel - Create drop down list on certain cells," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).

0 Comments