Trouble Setting Range

P

Pablo

I am trying to establish the end of a range but keep running into an object
error. Below is a bit of code that and the error, "Method 'Range' of object
'_Global' failed.

Dim Drng As Long
Dim RngEnd As String

Drng = ActiveSheet.Cells(Rows.Count, "G").End(xlUp).Row
....
Range("H5").Select
RngEnd = "H" & Drng

Selection.AutoFill Destination:=Range("H5:RngEnd")

Any help is appreciated.
 
J

Jim Cone

Selection.AutoFill Destination:=Range("H5:" & RngEnd)
--
Jim Cone
Portland, Oregon USA



"Pablo"
<[email protected]>
wrote in message
I am trying to establish the end of a range but keep running into an object
error. Below is a bit of code that and the error, "Method 'Range' of object
'_Global' failed.

Dim Drng As Long
Dim RngEnd As String

Drng = ActiveSheet.Cells(Rows.Count, "G").End(xlUp).Row
....
Range("H5").Select
RngEnd = "H" & Drng

Selection.AutoFill Destination:=Range("H5:RngEnd")

Any help is appreciated.
 
R

ryguy7272

Pablo, are you sure that RngEnd shouldn't be Dimmed as Long. I always Dim my
'last rows' as Long.
Dim RngEnd As Long

Jim gave good guidance above. I just would have changed the Data Type to
Long.

Just my two cents.

Good luck,
Ryan---
 
R

Rick Rothstein

For the way Pablo wrote his code, RngEnd needs to be a String; here is what
is being assigned to it...

RngEnd = "H" & Drng

Drng was Dim'med as a Long and that variable is what Pablo assigned the end
of data to.
 
P

Pablo

Ryan - Thank you. I see the value of this. It makes the variable more
versitable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top