end of row? in a macro :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

end of row? in a macro
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

puppawinnie
Board Regular


Joined: 10 Dec 2002
Posts: 11


Status: Offline

 Reply with quote  

I am using Excel 97 and I have written a macro will be applied to a number of spreadsheets with same formats but varying column lengths. Is there a bit of code that XL 97 will recognize as the end of a column that I can replace in my Macro(eg instead of Range (A2:A89)(for argument sake) so that each worksheet will see this as the end of column and I won't have to manually change that line for each spreasheet?

Post Sat Feb 15, 2003 5:09 pm 
 View user's profile Send private message

phantom1975
MrExcel MVP


Joined: 04 Jun 2002
Posts: 3518
Location: Glendale, Arizona
Flag: Usa

Status: Offline

 Reply with quote  

Here is what you need:

Range("A65536").End(xlUp).Row

This will give you the last cell in Column A that has data.

_________________
ClickHERE for a list of Excel functions and examples.

***************** EXCEL/VB NEWBIES ARE MY FAVORITE! *****************

Post Sat Feb 15, 2003 5:22 pm 
 View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger

bobm
Board Master


Joined: 12 Jan 2003
Posts: 359


Status: Offline

 Reply with quote  

Just to clarify Phantom's suggestion,

Range("A65536").End(xlUp).Row returns the row number of the last cell with data.

Range("A65536").End (xlUp) is the range of the last cell with data.

Bob

Post Sat Feb 15, 2003 5:30 pm 
 View user's profile Send private message

Nimrod
MrExcel MVP


Joined: 30 Apr 2002
Posts: 2530
Location: Vancouver BC , Canada

Status: Offline

 Reply with quote  

A little VBA demo for you :

Public Sub LastRowDemo()
LastRow = Range("A65536").End(xlUp).Row
NextEmptyRow = Range("A65536").End(xlUp).Row + 1

NL = Chr(13) & Chr(10)
ln1 = " In colA the Last Row Used is " & LastRow & NL
ln2 = " In colA the Last Row UnUsed is " & NextEmptyRow & NL
ln3 = " I will now select the used range for you..starting at A2" & NL
Title = "Last Row Demo"

pt = MsgBox(ln1 & ln2 & ln3, vbInformation, Title)

Range("A2:A" & LastRow).Select
End Sub


_________________
NOTE: (Testing performed on Win2K utilizing Office 2000. Solutions may need tweaking for other versions.)
Adieu,Nimrod

Post Sat Feb 15, 2003 5:44 pm 
 View user's profile Send private message AIM Address

puppawinnie
Board Regular


Joined: 10 Dec 2002
Posts: 11


Status: Offline

 Reply with quote  

Is the line "Range("A65536").End(xlUp).Row" going to replace "89" verbatim? This is what Bob is suggeting!?

Post Sat Feb 15, 2003 6:00 pm 
 View user's profile Send private message

Nimrod
MrExcel MVP


Joined: 30 Apr 2002
Posts: 2530
Location: Vancouver BC , Canada

Status: Offline

 Reply with quote  

PUP:

Look at the demo i've provided for you..

LastRow = Range("A65536").End(xlUp).Row
Range("A2:A" & LastRow).Select

Range("A65536").End(xlUp).Row will give you the row number

_________________
NOTE: (Testing performed on Win2K utilizing Office 2000. Solutions may need tweaking for other versions.)
Adieu,Nimrod
[ This Message was edited by: Nimrod on 2003-02-15 13:14 ]

Post Sat Feb 15, 2003 6:10 pm 
 View user's profile Send private message AIM Address

bobm
Board Master


Joined: 12 Jan 2003
Posts: 359


Status: Offline

 Reply with quote  

Here is what I was going to post in response to "PUP's" last question, but since it is pretty much identical to Nimrod's I decided not to.

Try this:

Dim lngLastRow As Long

lngLastRow = Range("A65536").End(xlUp).Row
Range ("A2:A" & lngLastRow)

Post Sat Feb 15, 2003 6:22 pm 
 View user's profile Send private message

puppawinnie
Board Regular


Joined: 10 Dec 2002
Posts: 11


Status: Offline

 Reply with quote  

Here's the relevant line of code as originally written "Selection.AutoFill Destination:=Range("B2:B89"), Type:=xlFillDefault then I replaced 89 with Range("A65536").End(xlUp).Row. I tried parentheses, quotes but I am still getting a syntax error. Please pardon my ignorance.

Post Sat Feb 15, 2003 6:32 pm 
 View user's profile Send private message

puppawinnie
Board Regular


Joined: 10 Dec 2002
Posts: 11


Status: Offline

 Reply with quote  

Here's the relevant line of code as originally written "Selection.AutoFill Destination:=Range("B2:B89"), Type:=xlFillDefault then I replaced 89 with Range("A65536").End(xlUp).Row. I tried parentheses, quotes but I am still getting a syntax error. Please pardon my ignorance.

Post Sat Feb 15, 2003 6:32 pm 
 View user's profile Send private message

Nimrod
MrExcel MVP


Joined: 30 Apr 2002
Posts: 2530
Location: Vancouver BC , Canada

Status: Offline

 Reply with quote  

LastRow = Range("A65536").End(xlUp).Row


Selection.AutoFill Destination:=Range("B2:" & LastRow & "), Type:=xlFillDefault "

[ This Message was edited by: Nimrod on 2003-02-15 13:39 ]

Post Sat Feb 15, 2003 6:38 pm 
 View user's profile Send private message AIM Address
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.