Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / General Excel Questions / May 2008

Tip: Looking for answers? Try searching our database.

Getting Compile error - on this line

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim May - 27 May 2008 16:11 GMT
Set rng = Range("D2:D"&Cells(rows.count,"D").end(xlUp).row & ")"

When I extract only
Cells(rows.count,"D").end(xlUp).row  and drop it in the Immediate window
preceeded with a ?

I get    9   << the correct row number

Can someone assist?
John Bundy - 27 May 2008 16:16 GMT
Try putting spaces on both sides of your first &. Typically to make
troubleshooting easier, set a variable to the value then use it like this:

LastRow=Cells(rows.count,"D").end(xlUp).row
Set rng = Range("D2:D" & LastRow & ")"

just all around easier that way.
Signature

-John
Please rate when your question is answered to help us and others know what
is helpful.

> Set rng = Range("D2:D"&Cells(rows.count,"D").end(xlUp).row & ")"
>
[quoted text clipped - 5 lines]
>
> Can someone assist?
Jim May - 27 May 2008 16:31 GMT
John - Thanks, but I'm still getting Compile error with your recommended
changes
made - here is my latest code

Dim rng As Range
Dim Lrow As Integer
Lrow = Cells(Rows.Count, "D").End(xlUp).Row
Set rng = Range("D2:D & Lrow & ")"

> Try putting spaces on both sides of your first &. Typically to make
> troubleshooting easier, set a variable to the value then use it like this:
[quoted text clipped - 13 lines]
> >
> > Can someone assist?
Don Guillett - 27 May 2008 16:34 GMT
try this
Set rng = Range("D2:D" & Lrow)
or
rng = Range("D2:D" & Lrow)

Signature

Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@austin.rr.com

> John - Thanks, but I'm still getting Compile error with your recommended
> changes
[quoted text clipped - 24 lines]
>> >
>> > Can someone assist?
bpeltzer - 27 May 2008 16:24 GMT
Not sure about the & ")" at the end...  I think you just need the closing
paren, since the paren isn't part of the string argument of the range
function:
Set rng = Range("D2:D" & cells(rows.count,"D").end(xlUp).row )

> Set rng = Range("D2:D"&Cells(rows.count,"D").end(xlUp).row & ")"
>
[quoted text clipped - 5 lines]
>
> Can someone assist?
Jim May - 27 May 2008 17:48 GMT
Thanks bpeltzer.  I have seen (before) instances where it was neccesary to end
such a range with the ")".  Can you explain why/when this may be necessary?
Tks,
Jim

> Not sure about the & ")" at the end...  I think you just need the closing
> paren, since the paren isn't part of the string argument of the range
[quoted text clipped - 10 lines]
> >
> > Can someone assist?
bpeltzer - 27 May 2008 21:17 GMT
I generally look at how I want the result to read (often by using the
immediate window as you suggested).  In this instance, the result should read
Range("D2:D9").  I think your original formula generated Range("D2:D9)
--Bruce

> Thanks bpeltzer.  I have seen (before) instances where it was neccesary to end
> such a range with the ")".  Can you explain why/when this may be necessary?
[quoted text clipped - 15 lines]
> > >
> > > Can someone assist?
Dave Peterson - 27 May 2008 22:39 GMT
I bet you've seen & ")" when you were building a formula that would be plopped
into a cell.

> Thanks bpeltzer.  I have seen (before) instances where it was neccesary to end
> such a range with the ")".  Can you explain why/when this may be necessary?
[quoted text clipped - 15 lines]
> > >
> > > Can someone assist?

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.