简体   繁体   中英

VBE How do you use Filldown with the WEEKNUM Function

I want cell E2 to pull the WEEKNUM from cell D2, and then repeat for the length of my data set.

Sub WeekNumTest()
Range("E2").Select
ActiveCell.FormulaR1C1 = "=WEEKNUM(RC[-1])"
Range("E2").Select
Selection.FillDown
End Sub

The weeknum is pulling correctly for cell E2, but the formula is not continuing for the rest of my data.

Use variables and find the extent of range.

Then set all the formulas at once.

Sub WeekNumTest()
Dim rng As Range
Dim ws As Worksheet

Set ws = ActiveSheet

Set rng = ws.Range(ws.Cells(2, 5), ws.Cells(ws.Cells(ws.Rows.Count, 4).End(xlUp).Row, 5))

Rng.FormulaR1C1 = "=WEEKNUM(RC[-1])"

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM