VBA select cells for data validation

Ambre

New Member
Joined
Sep 12, 2013
Messages
23
Hi,

What I am trying to do is a macro to validate some data into List.

I have several colonnes (19) and, for example, from cell B15 to last row I want to validate the data with the list List_HMG.
I wrote the code for each column but it is not running well because at the end of the macro, all selected cells during the marco have the same drop down list. I understand that the second selection is added to the first one, the third one to the second+first etc. I guess I need the cells to be selected indenpendtly and not keep in the selection the first cells selected (hope it makes sense).
Here is an extract from my code, if you have any ideas...

Rich (BB code):
Range("B15", Selection.End(xlDown)).Select
     With Selection.Validation
     .Delete
     .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=List_HMG"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
 
    Range("C15", Selection.End(xlDown)).Select
     With Selection.Validation
      .Delete
      .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=List_Buyers"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With


and if - Selection.End(xlDown)) -
is not right to go to the last row, please advise me :)

Other question:
There are several ranges to which I want to assign the same list.
How can I wrote the code?

Something like that?
Rich (BB code):
Range("B15", Selection.End(xlDown)) And Range("E15", Selection.End(xlDown)).Select 'i know this is not correct 
      .Delete
      .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=List_Yes_No"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With

To tell you the whole story, I first run a macro to add rows to this sheet but the new cells do not get the dropdown lists so I run this second macro to apply validation to the new cells and old ones also again.
I will add many rows in the existence of this file and I want the data validation to apply automatically.

Thank you
Ambre


I am a beginner in VBA
English is not my mother tongue
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Solution to my first problem
the code should be
Rich (BB code):
Range("B15").Select
    Range(Selection, Selection.End(xlDown)).Select
instead of
Rich (BB code):
Range("B15", Selection.End(xlDown)).Select
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,781
Members
448,992
Latest member
prabhuk279

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top