PDA

View Full Version : Help With Counting



drums4monty
09-27-2013, 03:13 AM
Hi All

I have written a macro that checks a serial number in one workbook and when it matches the number in another workbook copies the information in a column into the first workbook, this part works fine (I must be getting a little better at coding). What I need to do is tell the code that when it reaches the last row where data is, to finish. How do you do that? At the moment I just have a huge range which works but is not the correct way to do it I know.

Many thanks

Alan

patel
09-27-2013, 04:03 AM
LastRownumber = Sheets(1).Cells(Rows.Count, "A").End(xlUp).Row

mrojas
09-28-2013, 07:20 PM
I think you meant .End(xlDown).Row and not xlUp since you want to find where, at the bottom of column, is the last cell with a value.

patel
09-28-2013, 11:34 PM
did you test my code and your code ?

SamT
09-29-2013, 06:11 AM
Depends on your loop. Patel's with For i = r to LastRowNumber

With For Each Rng in Range(), then Set Range = Range("A1", LastRng) where LastRng = Sheets(1).Cells(Rows.Count, "A").End(xlUp)

If you're using Set Cell = Cell.Offset... , use IF Cell.Value = "" then stop.