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 / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Last Used Cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ryguy7272 - 24 Jan 2008 21:42 GMT
This snippet of code always fails on the ActiveSheet line

Dim LastR
   LastR = Cells(Rows.Count, "P").End(xlUp).Select
   ActiveSheet.PageSetup.PrintArea = "$A$1:LastR"

What is wrong?  I am just trying to find the last used cell in Column P, and
then set the Print Area as A1 to the last row in Column P that is used.

Argh!!

Signature

RyGuy

Jim Thomlinson - 24 Jan 2008 22:23 GMT
Try this...

   Dim LastR as long

   LastR = Cells(Rows.Count, "P").End(xlUp).Select
   ActiveSheet.PageSetup.PrintArea = "A1:P" & LastR

Signature

HTH...

Jim Thomlinson

> This snippet of code always fails on the ActiveSheet line
>
[quoted text clipped - 6 lines]
>
> Argh!!
ryguy7272 - 24 Jan 2008 22:51 GMT
Well, it certainly looks like it should work, but Excel doesn't like it.  It
gtes hung up in the same place.  What could it be?

Thanks,
Ryan--

Signature

RyGuy

> Try this...
>
[quoted text clipped - 13 lines]
> >
> > Argh!!
Dave Peterson - 24 Jan 2008 23:39 GMT
I don't think Jim saw that .Select lurking at the end of that second line:

   Dim LastR as long
   LastR = Cells(Rows.Count, "P").End(xlUp).Row  '<--changed to row
   ActiveSheet.PageSetup.PrintArea = "A1:P" & LastR

> Well, it certainly looks like it should work, but Excel doesn't like it.  It
> gtes hung up in the same place.  What could it be?
[quoted text clipped - 30 lines]
> > > --
> > > RyGuy

Signature

Dave Peterson

Jim Thomlinson - 24 Jan 2008 23:05 GMT
you want the row so get rid of the select...

   Dim LastR as long

   LastR = Cells(Rows.Count, "P").End(xlUp).Row 'Row not Select
   ActiveSheet.PageSetup.PrintArea = "A1:P" & LastR

Signature

HTH...

Jim Thomlinson

> Try this...
>
[quoted text clipped - 13 lines]
> >
> > Argh!!
Gord Dibben - 24 Jan 2008 23:10 GMT
Dim LastR As Long
   LastR = Cells(Rows.Count, "P").End(xlUp).Row
   ActiveSheet.PageSetup.PrintArea = "$A$1:P" & LastR

Gord Dibben  MS Excel MVP

>This snippet of code always fails on the ActiveSheet line
>
[quoted text clipped - 6 lines]
>
>Argh!!
ryguy7272 - 25 Jan 2008 14:21 GMT
I knew when Jim Thomlinson got involved this issue would be resolved!!  Also,
thanks for the help Gord and Dave!!  This must have been such a simple thing
for three gurus, but for me it was somewhat troublesome.  Oh well, I learned
a new trick today.

Thanks again guys!
Ryan---

Signature

RyGuy

> Dim LastR As Long
>     LastR = Cells(Rows.Count, "P").End(xlUp).Row
[quoted text clipped - 12 lines]
> >
> >Argh!!
 
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.