VBA dropdown list error

R2ah1ze1l

Board Regular
Joined
Nov 10, 2017
Messages
93
Code:
    With wsReview.Range(Cells(9, 20), Cells(9, ic + lastr)).Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _    <---Highlight in yellow
        Operator:=xlBetween, Formula1:="Pool"                             <---Arrow on this line
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With

I am receiving a Run-time error '1004': Application-defined or object-defined error
I copied this from a recorded macro then edited the range selection.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
No matter what I change these two lines are highlight yellow:
Code:
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=$A$1"
and there is an arrow pointing to this line:
Code:
        xlBetween, Formula1:="=$A$1"

Do I need to declare something?
 
Upvote 0
Your code works, I would check if the range is what you want.

I would check the values for ic and lastr and the sum doesn't go below 1.

When you debug, hover mouse over ic and lastr, or just add a watch for (ic + lastr). You can also write ? ic, ? lastr or ? ic + lastr etc in the Immediate window
 
Upvote 0
Your code works, I would check if the range is what you want.

I would check the values for ic and lastr and the sum doesn't go below 1.

When you debug, hover mouse over ic and lastr, or just a watch ic + lastr
ic = 19
lastr = 109

for this example (this was with a mouse hover over)
 
Upvote 0
Just changed first line here: With ActiveSheet.Range(Cells(1, 4), Cells(2, 5)).Validation

Any protection on the sheet maybe?

Also, just an observation, lastr as in LastRow? So on row 9, from columns 20 to 128, is that what you want?
 
Upvote 0
I have not protected any cells/worksheets/workbooks, manually or via vba.
In this instance, yes I want the list box applied along row 9 from column 20 to 128.

Every time I try the error flags the formula1 line...
 
Upvote 0
Can you try writing that line in 1 line?
As in:
VBA Code:
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Pool"
 
Upvote 0
Still results in 1004 error: Application-defined or object-defined error
And as one line it is all highlight with an arrow pointed to it.

Yes, this is the active sheet.
 
Upvote 0
Is the code an a standard module or a sheet module? Can't think of anything else other than use fully qualified cell references as well.

VBA Code:
With wsReview.Range(wsReview.Cells(9, 20), wsReview.Cells(9, ic + lastr)).Validation
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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