OilEconomist
Active Member
- Joined
- Dec 26, 2016
- Messages
- 439
- Office Version
- 2019
- Platform
- Windows
Hello and thanks in advance for your assistance. I would like to make a data validation on a particular sheet by extracting entries from a column on another sheet. I would also like to eliminate any duplicate values from the list.
My issue is how to get the values to appear in the formula bar. I would like to not use name ranges. I am having issues with the following line of code.
So basically is there some way for it to automatically extract and input the values into the formula to get this:
The code is as follows. Also, how much does the code change if it needs to eliminate any duplicates values from the range. In terms of ensuring that none of the values repeat themselves in the data validation?
My issue is how to get the values to appear in the formula bar. I would like to not use name ranges. I am having issues with the following line of code.
VBA Code:
Sheets("Plan.Loader").Range("A7").Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:=RngDatVal
So basically is there some way for it to automatically extract and input the values into the formula to get this:
VBA Code:
Sheets("Plan.Loader").Range("A7").Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:="Dog,Cat,Bird,Mouse"
The code is as follows. Also, how much does the code change if it needs to eliminate any duplicates values from the range. In terms of ensuring that none of the values repeat themselves in the data validation?
VBA Code:
Sub DatVal()
'Dimensioning
Dim ShtNm As String
Dim LastRow As Long
Dim RngDatVal As Range
Sheets("Plan.Loader").Activate
'Code
ShtNm = "Plan.2022.02.28"
With Sheets(ShtNm)
Set RngDatVal = .Range("C9:C17")
End With
Sheets("Plan.Loader").Range("A7").Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Formula1:=RngDatVal
End Sub
Last edited by a moderator: