Vba 即使在使用 "itemwidth" 偏移后仍采用原始选择

Vba is taking the original Selection even after offset with "itemwidth"

我正在构建一个宏,它可以找到一个 header,然后将其偏移 1 行,我想为整列填充一个值。但是当我 运行 宏正在将偏移值更改为 Required 但是一旦它到达 Selection.filldown 它就会复制 header 代替偏移值。如果找不到选择,我也无法弄清楚如何跳过。谁能帮忙解决这个问题?

Sub Macro7()
Rows("3:3").Select
Selection.Find(What:="item_width").Select
Selection.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = "1"
Selection.FillDown
End Sub

正如 Christmas007 所说,删除 .select.activate:

    Sub Macro7()
    Dim rng As Range
    Dim rws As Long
    rws = Range("A" & Rows.Count).End(xlUp).Row - 2
    Set rng = Rows("3:3").Find(What:="item_width")
    If Not rng Is Nothing Then
        rng.Offset(1, 0).FormulaR1C1 = "1"
        rng.Offset(1, 0).Resize(rws).FillDown
    End If
End Sub

还有你填充的方式,因为它只是一个单元格,所以它用正上方的单元格填充它。要填充一个范围,您需要指定范围范围。以上是一种方式。