Best way to determine rows with data

kpierce

Board Regular
Joined
Jun 21, 2010
Messages
76
I need to take a snapshot of a sheet and then copy it into a PowerPoint. I have all that working great..

In order to do this, I have to determine how many rows contain data in the current sheet. What I am doing is looping through the rows looking for data in a certain cell. Again, this works but it seems there might be a more efficent way of doing this...

Here is the code I currently have.
Code:
   iRows = 4 ' start at row 4 to account for heading
   Do While iRows < 200 'only count upto 200 rows
        If ws.Range("A" & iRows) = "" And ws.Range("C" & iRows) = "" Then
           Exit Do
         Else
          iRows = iRows + 1
       End If
   Loop

I then use iRows as my range of rows to take the snapshot.

Thanks for the help..
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try

Code:
iRows = WorksheetFunction.Min(200, ws.Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row)
 
Upvote 0
maybe
Code:
set w = worksheetfunction
iRows = w.max(w.counta(A4:A200),w.counta(C4:C200))
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top