Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default VBA - Determine last cell in range?

I have a number of rows on an Excel worksheet. I'm writing a macro to loop
through each row and process the info on that row. The number of rows can be
variable.

How do I determine how many rows are in use? When I type CTRL-END, the sheet
knows how many rows to go down. I'd like that capability in my macro.

How I loop now... Which always ends up creating 999 rows, even if I only
have 10 rows of data.

'Create an object to work with our sheet
Set sht = Excel.Sheets(1)

'Loop through all the rows from 11 to 999
For Each fromCell In sht.Range("D11:D999")

Thanks!


  #2   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA - Determine last cell in range?

Try


For Each frmCell In Application.Intersect( _
ActiveSheet.UsedRange, Columns(4)).Cells


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Noozer" wrote in message
news:chKLf.66589$sa3.30172@pd7tw1no...
I have a number of rows on an Excel worksheet. I'm writing a
macro to loop through each row and process the info on that row.
The number of rows can be variable.

How do I determine how many rows are in use? When I type
CTRL-END, the sheet knows how many rows to go down. I'd like
that capability in my macro.

How I loop now... Which always ends up creating 999 rows, even
if I only have 10 rows of data.

'Create an object to work with our sheet
Set sht = Excel.Sheets(1)

'Loop through all the rows from 11 to 999
For Each fromCell In sht.Range("D11:D999")

Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel
external usenet poster
 
Posts: 74
Default VBA - Determine last cell in range?

Noozer,

Use sht.Cells(11,4).End(xlDown)

You can also use xlToLeft, xlToRight or xlUp if you want to navigate in
another direction.

Regards,

Chris.

--
Chris Marlow
MCSD.NET, Microsoft Office XP Master


"Noozer" wrote:

I have a number of rows on an Excel worksheet. I'm writing a macro to loop
through each row and process the info on that row. The number of rows can be
variable.

How do I determine how many rows are in use? When I type CTRL-END, the sheet
knows how many rows to go down. I'd like that capability in my macro.

How I loop now... Which always ends up creating 999 rows, even if I only
have 10 rows of data.

'Create an object to work with our sheet
Set sht = Excel.Sheets(1)

'Loop through all the rows from 11 to 999
For Each fromCell In sht.Range("D11:D999")

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
use active cell to determine range Gizmo Excel Discussion (Misc queries) 2 March 31st 08 04:55 AM
Value of cell to determine range in MAX Function [email protected] Excel Worksheet Functions 8 February 18th 06 06:34 PM
Determine if Cell Address is within a Range John Michl Excel Worksheet Functions 4 December 22nd 05 07:59 PM
Can VBA determine if a cell/range is in a group? BlindGuardian Excel Programming 7 June 10th 05 08:12 PM
Can VBA determine if a cell/range is in a group? Ron Coderre[_11_] Excel Programming 0 June 10th 05 06:49 PM


All times are GMT +1. The time now is 11:27 AM.

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"