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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,215,375
Messages
6,124,578
Members
449,174
Latest member
chandan4057

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