![]() |
Find last row through a macro
I have data in column A. The last row filled is row number 20
I have a formula in cell C1. I want to detect the last filled row in column A (in this example, it is row no.20) Once the detection is over, the vba should drag formula in C1 till C20. The next day I will paste some more data in column A. After running the same macro, again the same thing should happen. Detect the NEW last row number and drag formula from C1 till CXX (XX=NEW last row) Can anybody help? |
Find last row through a macro
If I can assume that you have no empty cells between A1 and the 'last
row' then:- Sub FillFormulasToLastRow() [A1].Select Do Until IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Loop ActiveCell.Offset(-1, 0).Select qend = ActiveCell.Row [C1].Copy Range("C2:C" & qend) End Sub somethinglikeant wrote: I have data in column A. The last row filled is row number 20 I have a formula in cell C1. I want to detect the last filled row in column A (in this example, it is row no.20) Once the detection is over, the vba should drag formula in C1 till C20. The next day I will paste some more data in column A. After running the same macro, again the same thing should happen. Detect the NEW last row number and drag formula from C1 till CXX (XX=NEW last row) Can anybody help? |
Find last row through a macro
Wonderful. Thanks.
Is there anyway to track how many empty cells are there between A1 and the last row? somethinglikeant wrote: If I can assume that you have no empty cells between A1 and the 'last |
Find last row through a macro
No worries, I'm getting a bit smarter with this one.
qend is now the last row, even if there are empty cells in between Sub HowManyEmptyCells() qend = [A65536].End(xlUp).Row Range("A" & qend).Select: x = 0 For i = qend To 1 Step -1: Range("A" & i).Select If IsEmpty(ActiveCell) Then x = x + 1 Next i MsgBox x & " Empty Cells" End Sub somethinglikeant wrote: Wonderful. Thanks. Is there anyway to track how many empty cells are there between A1 and the last row? somethinglikeant wrote: If I can assume that you have no empty cells between A1 and the 'last |
Find last row through a macro
Try this:
Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown Explanation: Range("C1", -is what to filldown Range("A1").End(xlDown) -is how far to filldown (End of column A) ..Offset(0, 2) -is which column from Range("A1") to filldown (2 columns to the right =C) Mike F wrote in message ps.com... I have data in column A. The last row filled is row number 20 I have a formula in cell C1. I want to detect the last filled row in column A (in this example, it is row no.20) Once the detection is over, the vba should drag formula in C1 till C20. The next day I will paste some more data in column A. After running the same macro, again the same thing should happen. Detect the NEW last row number and drag formula from C1 till CXX (XX=NEW last row) Can anybody help? |
Find last row through a macro
Super !!! Just a one liner. Will this solve the above problem? (if
there are empty cells in between A1 and last row in column A) Mike Fogleman wrote: Try this: Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown Explanation: Range("C1", -is what to filldown Range("A1").End(xlDown) -is how far to filldown (End of column A) .Offset(0, 2) -is which column from Range("A1") to filldown (2 columns to the right =C) Mike F |
Find last row through a macro
delete the rows with empty cells first then fill down
Sub Macro1() qend = [A65536].End(xlUp).Row Range("A" & qend).Select: For i = qend To 1 Step -1: Range("A" & i).Select If IsEmpty(ActiveCell) Then ActiveCell.EntireRow.Delete Next i qend = [A65536].End(xlUp).Row Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown 'nice one mike End Sub somethinglikeant wrote: Super !!! Just a one liner. Will this solve the above problem? (if there are empty cells in between A1 and last row in column A) Mike Fogleman wrote: Try this: Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown Explanation: Range("C1", -is what to filldown Range("A1").End(xlDown) -is how far to filldown (End of column A) .Offset(0, 2) -is which column from Range("A1") to filldown (2 columns to the right =C) Mike F |
Find last row through a macro
Combination of both. Great !! Thank you to both of you. Really
appreciate somethinglikeant wrote: delete the rows with empty cells first then fill down Sub Macro1() qend = [A65536].End(xlUp).Row Range("A" & qend).Select: For i = qend To 1 Step -1: Range("A" & i).Select If IsEmpty(ActiveCell) Then ActiveCell.EntireRow.Delete Next i qend = [A65536].End(xlUp).Row Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown 'nice one mike End Sub somethinglikeant |
Find last row through a macro
No, that also assumes no missing data in column A and will only filldown to
the row above the blank cell. This will filldown to the last used cell in column A, but will also put the formula opposite a blank cell. Range("C1", Cells(Rows.Count, "A").End(xlUp)).Offset(0, 2).FillDown Basically same explanation except now we determine how far up column A do we want to filldown in column C. Mike F wrote in message oups.com... Super !!! Just a one liner. Will this solve the above problem? (if there are empty cells in between A1 and last row in column A) Mike Fogleman wrote: Try this: Range("C1", Range("A1").End(xlDown)).Offset(0, 2).FillDown Explanation: Range("C1", -is what to filldown Range("A1").End(xlDown) -is how far to filldown (End of column A) .Offset(0, 2) -is which column from Range("A1") to filldown (2 columns to the right =C) Mike F |
All times are GMT +1. The time now is 09:57 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com