VBA drop-down validation applying to entire sheet

RompStar

Well-known Member
Joined
Mar 25, 2005
Messages
1,200
Hi there, long time no post!

Office 365, Excel Version 1908.

I have this VBA that loops over all the sheets and I need it to insert different drop-down lists based on column ranges.

It runs without errors, but applies the drop-down to every single cells in each sheet, what am I doing wrong ?


VBA Code:
Sub add_drop_downs_2()

Dim LastRow As Long
Dim ws As Worksheet
   
For Each ws In ThisWorkbook.Sheets

LastRow = ws.Range("L" & Rows.Count).End(xlUp).Row ' Find out the Last Row of Stores Processed Paste

ws.Select

With ws.Range("V2:V" & LastRow).Validation
    .Delete 'delete previous validation
    .Add Type:=xlValidateList, Formula1:="Y,N"
End With

With ws.Range("W2:W" & LastRow).Validation
    .Delete 'delete previous validation
    .Add Type:=xlValidateList, Formula1:="Y,N"
End With

With ws.Range("X2:X" & LastRow).Validation
    .Delete 'delete previous validation
    .Add Type:=xlValidateList, Formula1:="Y,N"
End With

Next ws
   
Application.DisplayAlerts = False
Application.DisplayAlerts = True

MsgBox ("Finished...")
   
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
but applies the drop-down to every single cells in each sheet,

In which cells does the validation apply and which cells do you want to apply it?

For example, in which cells of column V should it be and in which cells did the macro apply?
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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