Forum Discussion
chahine
Jan 26, 2022Iron 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
why is that? please advise
- 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