Identifying the Last Column in a spreadsheet

S

SOS

Hi all,

I got the following code snippet from a previous post and would like
little help if possible:

*********************************************

' Find the last real row
Lastrow& = .Cells.Find(What:="*", SearchDirection:=xlPrevious
SearchOrder:=xlByRows).Row

' Find the last real column

LastCol% = .Cells.Find(What:="*", SearchDirection:=xlPrevious
SearchOrder:=xlByColumns).Column

********************************************

If my data (for example) is in Cells A1 through E3 the code above tell
me that Lastow& is "3" and that LastCol% is "5".

What I would like is for the code to tell me that LastCol% ="E" so tha
I can then select the whole range of data ("A1:E3").

Can anybody give me some pointers please.

TIA

Seamu
 
S

SOS

It's OK, folks. I worked it out.

All I needed were the lines:

lastcell = Cells(LastRow&, LastCol%).Address
Range("A1", lastcell).Select

and the correct range was selected.

Thanks anyway

Seamu
 
P

...Patrick

Hello,
if your data are adjacent ("contigue" in french)

Selection.CurrentRegion.Select
adr = Selection.Address


--
....Patrick
Quoi que vous fassiez, faites le bien .
Mail: http://cerbermail.com/?KPW0tTCjFw
Connectez vous sur ce forum par :
news://msnews.microsoft.com/microsoft.public.fr.excel
 
D

Don Guillett

or this might work
Range("A1:"&lastcol%&lastrow&).Select

but you probably don't need to SELECT to do what you want to do next.
 
T

Tom Ogilvy

Just a heads up:

since lastCol is an integer, I don't believe your suggestion would work
correctly.

if lastcol was 21 and lastrow was 10 it would resolve to

Range("A1:2110").Select


--
Regards,
Tom Ogilvy


Don Guillett said:
or this might work
Range("A1:"&lastcol%&lastrow&).Select

but you probably don't need to SELECT to do what you want to do next.
 
D

Don Guillett

correct, as usual, so I would change to:
range(cells(1,1),cells(lastrow,lastcol)).select

--
Don Guillett
SalesAid Software
(e-mail address removed)
Tom Ogilvy said:
Just a heads up:

since lastCol is an integer, I don't believe your suggestion would work
correctly.

if lastcol was 21 and lastrow was 10 it would resolve to

Range("A1:2110").Select
 

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