Please help with Dropdown list error

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
424
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Trying to create a dropdown list but it`s saying Run Time Error 1004

VBA Code:
Sub BO_Drop_DownList()

   Dim ws      As Worksheet
   Dim Sws     As Worksheet
   Dim Rng     As Variant
   Dim LRow    As Long
   Dim STRws   As String


   Set Sws = ThisWorkbook.Worksheets("Summary")
   Set ws = ActiveSheet
   LRow = ws.Range("J2").End(xlDown).Row
   STRws = "='ws'!J2:J" & LRow
   
   If ws.Name <> "Summary" And ws.Name <> "Trend" And ws.Name <> "Supplier BO" And ws.Name <> "Dif Depot" Then

    ws.Range("J2:J" & LRow).Select

    With Selection.Validation
        .Delete
        .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
        :=xlBetween
        .IgnoreBlank = True
        .InCellDropdown = True

    End With

     Sws.Activate
     Sws.Range("A4:A17").Select
     ws.Activate
     With Selection.Validation
     .Add Type:=xlValidateList, _
     AlertStyle:=xlValidAlertStop, _
     Operator:=xlBetween, _
     Formula1:=STRws
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = "All BOReason Codes"
    .ErrorTitle = "Wrong Code"
    .InputMessage = "Input Code"
    .ErrorMessage = "Check Summary Sheet Code For Correct Code"
    .ShowInput = True
    .ShowError = True

     End With

End If

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Which line of code is giving the error?

Do you have protection turned on for ActiveSheet?
 
Upvote 0
Hi to all.

Change this line to:
VBA Code:
STRws = "='" & ws.Name & "'!$J$2:$J$" & LRow
Note that you also need absolute reference for the range.
 
Upvote 0
Solution
Thanks for the positive feedback(y), glad we were of some help.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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