• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VB - Data Validation - Range

manoj_th

Member
Hi Excel Gurus,


I have created a macro for DATA Validation, in the code below there is range (Formula1:="=$F$2:$F$4"), instead of the range, I want to declare the list there itself like ("123","abcd","pokeman", etc). Request you please help me in this regard.


F2=123

F3=abcd

F4=pokeman


Sub Macro1()

With Selection.Validation

.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _

xlBetween, Formula1:="=$F$2:$F$4"

.IgnoreBlank = True

.InCellDropdown = True

.InputTitle = ""

.ErrorTitle = ""

.InputMessage = ""

.ErrorMessage = ""

.ShowInput = True

.ShowError = True

End With

End Sub
 
Just to be clear, code line should look like:

[pre]
Code:
xlBetween, Formula1:="abcd,123,pokemon"
[/pre]
If that still doesn't work, perhaps you could elaborate on what exactly is not working? (wrong thing, code errors out, something else?)
 
xlBetween, Formula1:="=$F$2:$F$4"

should be

xlBetween, Formula1:="abcd,123,pokemon"
 
Sir,


I want the list like : "1. abc, xyz, 2542", "2. efg, ujf, 952"

separately (i.e; two selections only). Its breaking after the comma (,).

I need

"1........."

"2........."

request you to provide the solution.
 
Manoj_th


As I read your question, Lukes answer works.


Can you please post a sample workbook with some notes and examples of what your trying to achieve


Thanx
 
Hi Manoj ,


There is no solution to this problem , since the comma is used as a list item separator.


The workaround is given in the following link :


http://www.pcreview.co.uk/forums/need-help-excel-validation-lists-t3030535.html


In brief , it is to replace all the commas in your list items by the character CHR(130).


For example , make your first item as :


"1. abc" & CHR(130) & " xyz" & CHR(130) & " 2542"


The second item will be :


"2. efg" & CHR(130) & " ujf" & CHR(130) & " 952"


The complete code will be :

[pre]
Code:
Sub Macro1()
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="1. abc" & Chr(130) & " xyz" & Chr(130) & " 2542,2. efg" & Chr(130) & " ujf" & Chr(130) & " 952"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
[/pre]

Narayan
 
Back
Top