简体   繁体   English

VBE如何使用WEEKNUM函数的Filldown

[英]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. 我希望单元格E2从单元格D2拉出WEEKNUM,然后重复我的数据集的长度。

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. 周期正在为细胞E2正确拉动,但该公式不会继续用于我的其余数据。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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