user2674568
user2674568

Reputation: 21

Excel VBA: 'excel vba run-time error 1004' application-defined or object-defined error

I have this line in a module and it keeps spitting up a run-time error 1004 when I try and run it.

Can anyone help?

I'm guessing it's to do with how the Range is referenced, but i'm not sure. This is all new to me.

rngFirst = ThisWorkbook.Worksheets("Still In Progress").Range("G" & 1 & ":G" & lw)

Many thanks in advance

Upvotes: 0

Views: 16868

Answers (2)

Dave
Dave

Reputation: 316

This works for me:

Sub Button1_Click()

Dim rngFirst As Range
Dim int1 As Integer

int1 = 2

Set rngFirst = ThisWorkbook.Worksheets("Sheet1").Range("G" & 1 & ":G" & int1)

rngFirst.Select

End Sub

I was getting the same error as you until I used Dim and Set.

Upvotes: 1

mcalex
mcalex

Reputation: 6778

Your range is not defined correctly. Essentially, you are setting the range to:

"Still In Progress!G1:G1w".

You need to set the last bit of the rngFirst formula to a number (eg at the bottom right hand corner of the range). Something like:

...Range("G" & 1 & ":G" & 20)

if the bottom of your data is at row 20.

Upvotes: 1

Related Questions