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
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,618
Office Version
  1. 2007
Platform
  1. Windows
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,127,121
Messages
5,622,861
Members
415,935
Latest member
kes1973

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
Top