Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro - relative end of data

I want to create a macro that looks for the last ROW of data (which will
always vary) and allows me to copy and paste columns of real data between
spreadsheets. When I RECORD a macro to study the code, it always gives me an
absolute cell reference. How can I modify that macro to point to the
relative end of data? Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro - relative end of data


cLastRow = Cells(Rows.Count,"A").End(xlUp).Row

you can then use that in a Range statements, like

Range("A" & cLAstRow)

or something similar

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nancy C" wrote in message
...
I want to create a macro that looks for the last ROW of data (which will
always vary) and allows me to copy and paste columns of real data between
spreadsheets. When I RECORD a macro to study the code, it always gives me

an
absolute cell reference. How can I modify that macro to point to the
relative end of data? Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro - relative end of data

Thanks for the speedy reply, Bob. I'll give it a try!

"Bob Phillips" wrote:


cLastRow = Cells(Rows.Count,"A").End(xlUp).Row

you can then use that in a Range statements, like

Range("A" & cLAstRow)

or something similar

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nancy C" wrote in message
...
I want to create a macro that looks for the last ROW of data (which will
always vary) and allows me to copy and paste columns of real data between
spreadsheets. When I RECORD a macro to study the code, it always gives me

an
absolute cell reference. How can I modify that macro to point to the
relative end of data? Thanks!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro - relative end of data

Bob - that worked great! Thanks. Of course, I have another question! What
would be the code to find the last COLUMN of data? I tried to modify your
code, but the END statement is tripping me up (I think!). Thanks much. What
I'm trying to do is construct the actual last CELL of information.

"Bob Phillips" wrote:


cLastRow = Cells(Rows.Count,"A").End(xlUp).Row

you can then use that in a Range statements, like

Range("A" & cLAstRow)

or something similar

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nancy C" wrote in message
...
I want to create a macro that looks for the last ROW of data (which will
always vary) and allows me to copy and paste columns of real data between
spreadsheets. When I RECORD a macro to study the code, it always gives me

an
absolute cell reference. How can I modify that macro to point to the
relative end of data? Thanks!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro - relative end of data

The last cell of a used range is best found with

Dim LastRow As Long
Dim LastCol As Long
Dim LastCell As Range
LastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
LastCol = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
Set LastCell = Cells(LastRow, LastCol)

The reason for this is that last cell may be empty (say A25 has data, H20
has data, but the last cell in that area is H25), and the previous method
won't find empty cells.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nancy C" wrote in message
...
Bob - that worked great! Thanks. Of course, I have another question!

What
would be the code to find the last COLUMN of data? I tried to modify your
code, but the END statement is tripping me up (I think!). Thanks much.

What
I'm trying to do is construct the actual last CELL of information.

"Bob Phillips" wrote:


cLastRow = Cells(Rows.Count,"A").End(xlUp).Row

you can then use that in a Range statements, like

Range("A" & cLAstRow)

or something similar

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nancy C" wrote in message
...
I want to create a macro that looks for the last ROW of data (which

will
always vary) and allows me to copy and paste columns of real data

between
spreadsheets. When I RECORD a macro to study the code, it always

gives me
an
absolute cell reference. How can I modify that macro to point to the
relative end of data? Thanks!






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Relative Macro DanP Excel Discussion (Misc queries) 6 March 17th 09 02:58 PM
relative value in macro Janett Excel Discussion (Misc queries) 2 April 4th 06 05:42 PM
Relative Reference in a Macro DRH Excel Programming 2 December 31st 04 02:20 PM
MACRO Relative Reference Ibrahim Awwad Excel Programming 3 September 9th 03 02:11 PM
relative ref. macro J.E. McGimpsey Excel Programming 0 July 28th 03 05:03 PM


All times are GMT +1. The time now is 07:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"