Last row in range

User avatar
ErikJan
BronzeLounger
Posts: 1246
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Last row in range

Post by ErikJan »

If I have a range, e.g. Range("A2:A5000"), how do I get the last row (5000) in a variable? I tried "Specialcells(xlCellTypeLastCell)" but that gave me something like 5348... odd...

User avatar
StuartR
Administrator
Posts: 12609
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Last row in range

Post by StuartR »

Assume that you have a named range, MyRange, then the last row would be
Range("MyRange").Rows.Count + Range("MyRange").Row - 1

If you have a variable rngHereitis then you can use rngHereitis instead of Range("MyRange") in that example
StuartR


User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Last row in range

Post by HansV »

By the way, Erik Jan, your mail server is bouncing the e-mail notifications of replies to your questions as spam...
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1246
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Last row in range

Post by ErikJan »

StuartR wrote:Assume that you have a named range, MyRange, then the last row would be
Range("MyRange").Rows.Count + Range("MyRange").Row - 1

If you have a variable rngHereitis then you can use rngHereitis instead of Range("MyRange") in that example
Works, thank you

User avatar
ErikJan
BronzeLounger
Posts: 1246
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Last row in range

Post by ErikJan »

HansV wrote:By the way, Erik Jan, your mail server is bouncing the e-mail notifications of replies to your questions as spam...
Thanks Hans, working on it... if you reply to this one (as you know ;-))

User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Last row in range

Post by HansV »

OK, here you go.

This is a test to see if e-mail notifications are still rejected by your mail server.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Last row in range

Post by HansV »

Still bouncing. I've sent you a PM with the text of one of the failure messages.
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1246
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Last row in range

Post by ErikJan »

Should be fixed now... I added the sending address to a "Senders Whitelist" in my Spam filter. Thanks again for letting me know the emails bounced... :cheers:

User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Last row in range

Post by HansV »

Let's see - do you get a notification of this reply?
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1246
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Last row in range

Post by ErikJan »

Yes

User avatar
HansV
Administrator
Posts: 78494
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Last row in range

Post by HansV »

Good to hear that. Thanks for the confirmation.
Best wishes,
Hans