Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 2
Default for/next loop

I have a sheet in a workbook where I need to select the last row containing
data. Is there a for/next loop function where I can identify the last row,
then select data from it, or can I update two sheets simultaneously with one
input?
I am using Office 97, windows xp.

--



  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 10,124
Default for/next loop


sub getlastrow()
lr = Cells.Find(What:="*", After:=[A1],
SearchDirection:=xlPrevious).Row

cells(lr,"b").copy somewhere
end sub
If desired, send your file to my address below along with this msg and
a clear explanation of what you want and before/after examples.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Poor Richard" wrote in message
...
I have a sheet in a workbook where I need to select the last row containing
data. Is there a for/next loop function where I can identify the last row,
then select data from it, or can I update two sheets simultaneously with
one input?
I am using Office 97, windows xp.

--




  #3   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 5,934
Default for/next loop

You should specify SearchOrder:=xlRows, otherwise if the last Find a user
did was "By Columns", your code might find the wrong cell (on a blank sheet,
put something in A12 and C10 and run your code after having performed an
Edit/Find using "By Columns"). Also, if the After parameter is not provided,
Find automatically uses the cell at the top right of the search range (which
is A1 for the Cells range). This is what I use...

LastUsedRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious).Row

Of course, ActiveSheet could be left off if the code is to be applied
against the ActiveSheet, but when running from a macro installed in a
Module, that is not always a given. And, of course, ActiveSheet could be
replaced with a direct sheet reference such as Worksheets("Sheet1") if the
search is to be performed against a non-active sheet.

--
Rick (MVP - Excel)


"Don Guillett" wrote in message
...

sub getlastrow()
lr = Cells.Find(What:="*", After:=[A1],
SearchDirection:=xlPrevious).Row

cells(lr,"b").copy somewhere
end sub
If desired, send your file to my address below along with this msg
and a clear explanation of what you want and before/after examples.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Poor Richard" wrote in message
...
I have a sheet in a workbook where I need to select the last row
containing data. Is there a for/next loop function where I can identify
the last row, then select data from it, or can I update two sheets
simultaneously with one input?
I am using Office 97, windows xp.

--





  #4   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 5,934
Default for/next loop

Also, if the After parameter is not provided, Find automatically
uses the cell at the top right of the search range ..


Damn it Rick... read what you write. Of course I meant that Find
automatically uses the cell at the top LEFT of the specified search range.

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
You should specify SearchOrder:=xlRows, otherwise if the last Find a user
did was "By Columns", your code might find the wrong cell (on a blank
sheet, put something in A12 and C10 and run your code after having
performed an Edit/Find using "By Columns"). Also, if the After parameter
is not provided, Find automatically uses the cell at the top right of the
search range (which is A1 for the Cells range). This is what I use...

LastUsedRow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious).Row

Of course, ActiveSheet could be left off if the code is to be applied
against the ActiveSheet, but when running from a macro installed in a
Module, that is not always a given. And, of course, ActiveSheet could be
replaced with a direct sheet reference such as Worksheets("Sheet1") if the
search is to be performed against a non-active sheet.

--
Rick (MVP - Excel)


"Don Guillett" wrote in message
...

sub getlastrow()
lr = Cells.Find(What:="*", After:=[A1],
SearchDirection:=xlPrevious).Row

cells(lr,"b").copy somewhere
end sub
If desired, send your file to my address below along with this msg
and a clear explanation of what you want and before/after examples.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Poor Richard" wrote in message
...
I have a sheet in a workbook where I need to select the last row
containing data. Is there a for/next loop function where I can identify
the last row, then select data from it, or can I update two sheets
simultaneously with one input?
I am using Office 97, windows xp.

--






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
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
if loop sippe Excel Discussion (Misc queries) 2 November 10th 08 09:45 AM
Do Loop Vs For Each jlclyde Excel Discussion (Misc queries) 3 September 29th 08 08:48 PM
do..loop Anna Excel Discussion (Misc queries) 6 June 20th 07 01:10 PM
How would I add a loop for this? [email protected] Excel Discussion (Misc queries) 3 September 18th 06 01:21 PM


All times are GMT +1. The time now is 04:46 PM.

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

About Us

"It's about Microsoft Excel"