ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding a validation list by code (https://www.excelbanter.com/excel-programming/336032-adding-validation-list-code.html)

Philippe Pons

Adding a validation list by code
 
Hi all,

I would like to install a validation list by code.
I get a snippet using the macro recorder.(see below)
However when I run the code, 2 problems ocur:
1- the list will not show 2 choices: YES and NO, but only one: YES;NO
2- YES is not selected, although I selected it during the recording of
the macro
Do you know how I should improve the code to have it do what I need?
TIA,
Philippe


With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=
_
xlBetween, Formula1:="YES;NO"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With



Tom Ogilvy

Adding a validation list by code
 
Sub AA()
With Selection.Validation
.Delete
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:="YES,NO"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Selection.Value = "Yes"
End Sub

the only way to select it is to enter that value in the cell.

--
Regards,
Tom Ogilvy

"Philippe Pons" wrote in message
...
Hi all,

I would like to install a validation list by code.
I get a snippet using the macro recorder.(see below)
However when I run the code, 2 problems ocur:
1- the list will not show 2 choices: YES and NO, but only one: YES;NO
2- YES is not selected, although I selected it during the recording of
the macro
Do you know how I should improve the code to have it do what I need?
TIA,
Philippe


With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,

Operator:=
_
xlBetween, Formula1:="YES;NO"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With





Philippe Pons

Adding a validation list by code
 
Thank's Tom, I'll test it.
Philippe


"Tom Ogilvy" a écrit dans le message de
...
Sub AA()
With Selection.Validation
.Delete
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:="YES,NO"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Selection.Value = "Yes"
End Sub

the only way to select it is to enter that value in the cell.

--
Regards,
Tom Ogilvy

"Philippe Pons" wrote in message
...
Hi all,

I would like to install a validation list by code.
I get a snippet using the macro recorder.(see below)
However when I run the code, 2 problems ocur:
1- the list will not show 2 choices: YES and NO, but only one:

YES;NO
2- YES is not selected, although I selected it during the recording

of
the macro
Do you know how I should improve the code to have it do what I need?
TIA,
Philippe


With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,

Operator:=
_
xlBetween, Formula1:="YES;NO"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With








All times are GMT +1. The time now is 06:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com