Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
1  
Do you have a sheet called 'Still In Progress'? - and is that 'ell doubleyew' after ":G" &? –  mcalex Aug 13 '13 at 9:57
 
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
 
Dim rngFirst As Range .. –  matzone Aug 13 '13 at 10:12
add comment

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.

share|improve this answer
 
thanks mcalex, that explanation was really helpful! –  user2674568 Aug 13 '13 at 13:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.