Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Find first empty row in a worksheet with a Macro


I have a macro that takes data from one sheet and adds it into a table
on another form, at the moment it all works fine as long as all fields
are filled in everytime a new entry is added. What I want is to be
able to have some fields blank, to do this I need to be able to find
the last row with data in any column on the first sheet, and the first
row with no data in any columns on the next sheet. Is there a simple
way this can be done.
At the moment I use this:

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select

but this will find the first empty fields and so doesn't necesarily
find all the data.

Thanks for any assistance.

J


--
JHalsall
------------------------------------------------------------------------
JHalsall's Profile: http://www.excelforum.com/member.php...o&userid=34382
View this thread: http://www.excelforum.com/showthread...hreadid=541627

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Find first empty row in a worksheet with a Macro

Using your approach,

Cells(1, Columns.Count).End(xlToLeft).Select
Cells(Rows.Count, ActiveCell.Column).End(xlUp).Select

although this is better

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)

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"JHalsall" wrote in
message ...

I have a macro that takes data from one sheet and adds it into a table
on another form, at the moment it all works fine as long as all fields
are filled in everytime a new entry is added. What I want is to be
able to have some fields blank, to do this I need to be able to find
the last row with data in any column on the first sheet, and the first
row with no data in any columns on the next sheet. Is there a simple
way this can be done.
At the moment I use this:

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select

but this will find the first empty fields and so doesn't necesarily
find all the data.

Thanks for any assistance.

J


--
JHalsall
------------------------------------------------------------------------
JHalsall's Profile:

http://www.excelforum.com/member.php...o&userid=34382
View this thread: http://www.excelforum.com/showthread...hreadid=541627



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Find first empty row in a worksheet with a Macro

I use this to find the last real used row:

Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlFormulas, _
LookAt:= xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlPrevious, _
MatchCase:=False).Row

The same can be used to return column or address.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Find first empty row in a worksheet with a Macro

Try Selection.CurrentRegion.Select
--
- K Dales


"JHalsall" wrote:


I have a macro that takes data from one sheet and adds it into a table
on another form, at the moment it all works fine as long as all fields
are filled in everytime a new entry is added. What I want is to be
able to have some fields blank, to do this I need to be able to find
the last row with data in any column on the first sheet, and the first
row with no data in any columns on the next sheet. Is there a simple
way this can be done.
At the moment I use this:

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select

but this will find the first empty fields and so doesn't necesarily
find all the data.

Thanks for any assistance.

J


--
JHalsall
------------------------------------------------------------------------
JHalsall's Profile: http://www.excelforum.com/member.php...o&userid=34382
View this thread: http://www.excelforum.com/showthread...hreadid=541627


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Find first empty row in a worksheet with a Macro

Here are some good comments on this from Rodney Powell:

http://www.beyondtechnology.com/geeks012.shtml



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
Using a macro to paste into first empty row in a new worksheet Bruce64 Excel Worksheet Functions 3 January 13th 08 08:18 PM
Change Macro to Find First Empty Cell Jenny B. Excel Discussion (Misc queries) 3 January 10th 08 03:25 AM
Calc cost pro rata (nested IF's and macro to find empty row) herbwarri0r Excel Worksheet Functions 2 June 19th 07 12:29 PM
how do i find and delete all empty rows in an excel worksheet AinSF Excel Worksheet Functions 3 September 1st 06 01:38 AM
Help creating part of a macro (find Empty column) Jay[_17_] Excel Programming 2 May 27th 04 08:46 PM


All times are GMT +1. The time now is 03:32 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"