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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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