我正在尝试将列从B1
向下拖动到数据集中的最后一行。 B1
将始终填充值,我需要复制该值并将[x“的次数粘贴到B
列的下方,具体取决于工作表上的行数。
Sub Button1test_Click()
Set src = Sheets("Sheet1")
Dim Lastrow As Long
Lastrow = Range("B" & Rows.Count).End(xlUp).Row
src.Range("B1:B" & Lastrow).Value = "B1"
End Sub
列B
应填充'lucord'x次数。
"B1"
是文本“ B1”,而不是对范围B1
的引用。
[这也是With...End With
块限定Range
调用的好用例-否则Lastrow
是从活动工作表中确定的,不一定是src
。
更改
Lastrow = Range("B" & Rows.Count).End(xlUp).Row
src.Range("B1:B" & Lastrow).Value = "B1"
to
With src
Lastrow = .Range("B" & .Rows.Count).End(xlUp).Row
.Range("B1:B" & Lastrow).Value = .Range("B1").Value
End With
EDIT:如果仅填充B1
,则Lastrow
= 1
。根据填充的列确定Lastrow
,例如列A:
Lastrow = .Range("A" & .Rows.Count).End(xlUp).Row