Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a range within a range

Status
Not open for further replies.

t16turbo

Programmer
Mar 22, 2005
315
GB
I have a macro that inserts two colmuns into the worksheet.

I need to be able to select these two columns up to the last row of the data range.

I tried something like this:

Code:
Dim LastRow As Object

Set LastRow = [a65536].End(xlUp)

Range("C1:"LastRow).Select

but it doesn't work, so I guess I am getting the wrong syntax here
note: the above was just to test by selecting one of the two new columns..

what should I be doing?
 
If it's 2 columns, it should refer to C and D ( you've got C and null - illegal anyway ) ... like this:
Code:
Range("C1:D"LastRow).Select


Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
it gives me a syntax error:
here's my complete code for that module
Code:
Sub selectvlookuprange()

Dim LastRow As Object

Set LastRow = [a65536].End(xlUp)

Range("C1:D"LastRow).Select

End Sub

is it anything to do with LastRow being defined as an object?
 
Oops left a "&" out :
Code:
Range("C1:D" & LastRow).Select


Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
:-(

now its saying "run-time error '1004'
method 'Range' of object '_Global' failed"

sometimes I really despise VBA!! (probably because I don't fully understand it)
 
Hi,

I'm not to sure if I understand what you want but I do somethign similar (to what I think you want) with this:

If your two columns were C & D and A has holds the data then:

Code:
'Specify the last row
A_variable = Cells(Rows.Count, "A").End(xlUp).Row    
'Specify Range
Range("C" & A_variable & ":D1").Select

Hope this helps?

Woody
 
that does the job!!!! :)

thank you both for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top