Cells(Rows.Count, 1).End(xlUp).Rows returns zero unless I add a new field

KevH

Board Regular
Joined
Apr 24, 2007
Messages
104
Howdy all,

I have a worksheet with log data that was pushed from Access into Excel. I have a single Data/Time field and a few number fields. I'm trying to select the last record (to use in a range) using the formula below.

i = TargetSheet.Cells(Rows.Count, 1).End(xlUp).Rows

However, If I use any of the existing fields, the result is always zero. If I insert a new field and add some records to it, I get that field's last row as you'd expect.

What am I missing here?

Thanks,
Kev.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Remove the "s"
Rich (BB code):
i = TargetSheet.Cells(Rows.Count, 1).End(xlUp).Row

lenze
 
Upvote 0
What are you trying to do??? POst your full code!!!
The 1 in your code limits the macro to only column "A".

lenze
 
Upvote 0
Here's the code so far.

Code:
Dim Range1 As Range
Dim Range2 As Range
Dim i As Integer
Dim TargetSheet As Worksheet
'---------------------
Set TargetSheet = Worksheets("Data")
i = TargetSheet.Cells(Rows.Count, 1).End(xlUp).Row
Set Range1 = TargetSheet.Cells(4, 1) 'move past three header rows
Set Range1 = Range1.Resize(i - Range1.Row + 1, 1)
'---------------------
For Each Range2 In Range1.Cells
'Do some stuff
Next Range2
 
Upvote 0
Also,

I'm aware that the 1 is the column indicator. I've tried adjusting it with and without the new row and in each case only the new row returned something other than zero.

Right now I'm only trying to select a range for the For Each loop. I've got this working in other WB's, but for some reason not in this one.

I thought it might have been a file type issue, but XlS, XLSX, and XLSM are all doing this.
 
Upvote 0
Maybe this will help.

In the old field:
- If I leave the data at its current row (49422), then it returns zero.
- If I cut the data (to say 10 rows) it STILL returns zero.

In the new field:
- If I fill data to the bottom row (49422), then it starts returning zero too.
- If I undo that (and cut the data back down 10 rows) it goes back to working correctly.
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

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