find last populated cell and autofill column- vba

whitoulias

Board Regular
Joined
Jun 22, 2012
Messages
153
[TABLE="width: 192"]
<colgroup><col style="width:48pt" span="3" width="64"> </colgroup><tbody>[TR]
[TD="width: 64"]DATA[/TD]
[TD="width: 64"]DATE
[/TD]
[TD="width: 64"] PRICE
[/TD]
[/TR]
[TR]
[TD="class: xl51"]DATA[/TD]
[TD="class: xl50, width: 64"]20120621[/TD]
[TD="class: xl52, align: right"] 118.1000
[/TD]
[/TR]
[TR]
[TD="class: xl51"]DATA[/TD]
[TD="class: xl50, width: 64"]20120621[/TD]
[TD="class: xl52, align: right"]149.7700[/TD]
[/TR]
[TR]
[TD="class: xl51"]DATA[/TD]
[TD="class: xl50, width: 64"][/TD]
[TD="class: xl52, align: right"]94.8900[/TD]
[/TR]
[TR]
[TD="class: xl51"]DATA[/TD]
[TD="class: xl50, width: 64"][/TD]
[TD="class: xl52, align: right"]137.5900[/TD]
[/TR]
[TR]
[TD="class: xl51"]DATA[/TD]
[TD="class: xl50, width: 64"][/TD]
[TD="class: xl52, align: right"]114.5500[/TD]
[/TR]
[TR]
[TD="class: xl51"]DATA[/TD]
[TD="class: xl50, width: 64"][/TD]
[TD="class: xl52, align: right"]145.2700[/TD]
[/TR]
[TR]
[TD="class: xl51"]DATA[/TD]
[TD="class: xl50, width: 64"][/TD]
[TD="class: xl52, align: right"]114.5500[/TD]
[/TR]
[TR]
[TD="class: xl51"]DATA[/TD]
[TD="class: xl50, width: 64"][/TD]
[TD="class: xl52, align: right"]92.4000
[/TD]
[/TR]
[TR]
[TD="class: xl51"]DATA[/TD]
[TD="class: xl50, width: 64"][/TD]
[TD="class: xl52, align: right"]145.2700[/TD]
[/TR]
</tbody>[/TABLE]

i have 3 columns (data, date & price)
What i would like to do is find the last populated cell in 'date' column and autofill it based on column 'data'.
The tricky thing is that the date form is text and while autofilling manually it changes
Any thoughts?

Thanx
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try

Code:
Sub atest()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("B2:B" & LR)
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
End With
End Sub
 
Upvote 0
Or:

Code:
With Range("B" & Rows.Count).End(xlUp)
    Range(.Offset(1, 0), Range("B" & Range("A" & Rows.Count).End(xlUp).Row)) = .Value
End With

Dom
 
Last edited:
Upvote 0
Code:
Sub FillData()
    Dim lastA As Long, lastB As Long
    
    lastA = Cells(Rows.Count, "A").End(xlUp).Row
    lastB = Cells(Rows.Count, "B").End(xlUp).Row
    
    If lastB < lastA Then
        Range("B" & lastB & ":B" & lastA).FillDown
    End If
    
End Sub
 
Upvote 0
Try

Code:
Sub atest()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("B2:B" & LR)
    .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
End With
End Sub

Perfect
thanx a lot
 
Upvote 0
Code:
Sub FillData()
    Dim lastA As Long, lastB As Long
    
    lastA = Cells(Rows.Count, "A").End(xlUp).Row
    lastB = Cells(Rows.Count, "B").End(xlUp).Row
    
    If lastB < lastA Then
        Range("B" & lastB & ":B" & lastA).FillDown
    End If
    
End Sub

It works fine
though it keeps the format in text
Thank you all
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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