VBA Find last cell in the column and autofill based on three other columns first values

bored622

New Member
Joined
Mar 2, 2022
Messages
43
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,
I'm trying to create a macro where when a user presses a button the value in cells A2, C2, and D2 copies and drops down and matches the last row of column B.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
In your title you state "autofill" and in your question you state "copy". The below is for default autofill.

VBA Code:
Sub AfillB()
    Dim LastRow As Long

    LastRow = Cells(Rows.Count, "B").End(xlUp).Row

    Range("A2").AutoFill Range("A2:A" & LastRow)
    Range("C2:D2").AutoFill Range("C2:D" & LastRow)
End Sub
 
Last edited:
Upvote 0
In your title you state "autofill" and in your question you state "copy". The below is for default autofill.

VBA Code:
Sub AfillB()
    Dim LastRow As Long

    LastRow = Cells(Rows.Count, "B").End(xlUp).Row

    Range("A2").AutoFill Range("A2:A" & LastRow)
    Range("C2:D2").AutoFill Range("C2:D" & LastRow)
End Sub
It worked, but I'm having issues with column A. Since the value has a number in it, it doesn't keep the same value from cell A2. Is there any way to fix that issue?
 
Upvote 0
Is there any way to fix that issue?
Try...
VBA Code:
Sub FillValue()
    Dim LastRow As Long

    LastRow = Cells(Rows.Count, "b").End(xlUp).Row

   Range("A3:A" & LastRow).Value = Range("A2").Value
   Range("C3:C" & LastRow).Value = Range("C2").Value
   Range("D3:D" & LastRow).Value = Range("D2").Value
End Sub
 
Upvote 1
Solution
Try...
VBA Code:
Sub FillValue()
    Dim LastRow As Long

    LastRow = Cells(Rows.Count, "b").End(xlUp).Row

   Range("A3:A" & LastRow).Value = Range("A2").Value
   Range("C3:C" & LastRow).Value = Range("C2").Value
   Range("D3:D" & LastRow).Value = Range("D2").Value
End Sub
This worked perfectly! Thank you
 
Upvote 0

Forum statistics

Threads
1,215,182
Messages
6,123,517
Members
449,102
Latest member
admvlad

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