VBA Code to fill down to next Cell

ajay_gajree

Well-known Member
Joined
Jul 16, 2011
Messages
518
Hi All,

I am trying to write a simple macro,

Sheets("Sheet1").Select
Range("B2").Select
Selection.End(xlDown).Select
Range("B18").Select
Selection.FillDown

My aim is to copy a formula in the last cell in Column B, so I recorded what I wanted with the above result,

So this is selecting a sheet and a cell and then uses control down arrow to go to the last cell with data in it in that Column,

I then wish to select the cell below and copy down using Control D

This is the bit that is wrong in the code as recorded macro is showing the specific cell B18, when I would like the first empty cell in the Column,

Any ideas?

Thanks and best regards

Ajay
 
Maybe like this

Code:
Dim LR As Long
With Sheets("Sheet1")
    LR = .Range("B" & Rows.Count).End(xlUp).Row
    .Range("B" & LR).Resize(2).FillDown
End With
I believe this could be use as well with the same results...

Code:
With Sheets("Sheet1").Range("B" & Rows.Count).End(xlUp)
  .Copy .Offset(1)
End With
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Maybe like this

Code:
Sub Excel_Model()
 
Dim LR As Long, i As Long
 
 
With Sheets("Excel Model")
    .Range("A3").Value = Date
    LR = .Range("B" & Rows.Count).End(xlUp).Row
    For i = 3 To LR
        With .Range("B" & i)
            If .Value >= Date Then .ClearContents
        End With
    Next i
    .Range("B" & LR).Resize(2).FillDown
End With
 
End Sub



VoG: Thanks! This helped me 6 years later...
 
Upvote 0

Forum statistics

Threads
1,224,612
Messages
6,179,890
Members
452,948
Latest member
Dupuhini

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