SOLVED

# vba cells

Frequent Contributor

# vba cells

hello

i have a question, like i want to find last row number in a used range so when i use this code

Debug.Print ActiveSheet.UsedRange.Cells(rows.count, 5).End(xlUp).Row

it gives an error, although rows.count should give 1048576

but when i use

Debug.Print ActiveSheet.UsedRange.Cells(1000000, 5).End(xlUp).Row it works fine and gives a number

2 Replies
best response confirmed by Hans Vogelaar (MVP)
Solution

# Re: vba cells

Range references are relative, so if your data is in A17:D30, then that is your usedrange. So, 1048576 rows down from row 17 is beyond excel's row limit and you'll get an error.

Try: ActiveSheet.Cells(rows.count, 5).End(xlUp).Row

# Re: vba cells

great thanks a lot !