VBA AutoFill Formula

Vin90

New Member
Joined
Oct 20, 2017
Messages
29
I'm currently working on small macro that can be used to autofill empty cells with certain formula, and I have two questions:

I create UserForm to input the data on the desired worksheet. I have assigned column A and E:AM for the input, and leave cloumn B:D empty.

In the data entry, I have date on column A, and wish to autofill column B,C and D with year, month, and weeknum of the corresponding date.

I'm using this code in modules group but somehow it doesn't work as expected:
Code:
Sub FillDown()
Dim strFormulas(1 To 3) As Variant
With ThisWorkbook.Sheets("Data")
    strFormulas(1) = "=YEAR(A2)"
    strFormulas(2) = "=MONTH(A2)"
    strFormulas(3) = "=ISOWEEKNUM(A2)"
    
    .Range("B2:D2").Formula = strFormulas
    .Range("B2:D" & lRow).FillDown
End With
End Sub

Questions:
1. Is there something wrong with the aforementioned code?
2. Is there any way to combine this autofill to the commandbutton_click in my userform?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You haven't assigned lRow a value, maybe add this

lRow = Cells(Rows.Count, 2).End(xlUp).Row
 
Upvote 0
It doesn't show the previous error, but it still doesn't work properly..
they copy the value from B1:D1 instead of the wanted formula.. :(

Code:
Sub FillDown()
Dim strFormulas(1 To 3) As Variant
With ThisWorkbook.Sheets("Data")
    strFormulas(1) = "=YEAR(A2)"
    strFormulas(2) = "=MONTH(A2)"
    strFormulas(3) = "=ISOWEEKNUM(A2)"
    lRow = Cells(Rows.Count, 2).End(xlUp).Row
        
    .Range("B2:D2").Formula = strFormulas
    .Range("B2:D" & lRow).FillDown
End With
End Sub
 
Upvote 0
May need to change the lRow line to this

Code:
lRow = .Cells(.Rows.Count, 1).End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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