VBA动态循环以填充列
我试图用1填充列的每一行,从标题后的第二行到最后一行。 在名为“成人”的工作表中,该列为“可以呼叫”。 这段代码在正确的工作表中创建我需要的列,但不使用1填充行。我想我必须在最后一行加上,但不知道怎么加。谢谢你的帮助VBA动态循环以填充列,vba,loops,dynamic,Vba,Loops,Dynamic,我试图用1填充列的每一行,从标题后的第二行到最后一行。 在名为“成人”的工作表中,该列为“可以呼叫”。 这段代码在正确的工作表中创建我需要的列,但不使用1填充行。我想我必须在最后一行加上,但不知道怎么加。谢谢你的帮助 Dim shtA As Worksheet Set shtA = ActiveWorkbook.Sheets("Adults") Dim LastCol As Long LastCol = shtA.Cells(1, Columns.Count).End(xlT
Dim shtA As Worksheet
Set shtA = ActiveWorkbook.Sheets("Adults")
Dim LastCol As Long
LastCol = shtA.Cells(1, Columns.Count).End(xlToLeft).Column
Dim lastRow As Long
lastRow = shtA.Cells(Rows.Count, 1).End(xlUp).Row
'Loop through heading row to get column number of "Ok to call?"
Dim okcall As Long
Dim a As Long
For a = 1 To LastCol
If LCase(shtA.Cells(1, a).Value) = "ok to call?" Then
okcall = a
Exit For
End If
Next a
在PeterT的建议后添加了以下内容:
For a = 1 + 1 To lastRow
shtA.Cells(a, okcall).Value = 1
Next a
End
您想用什么填充这些行?您需要在这个循环之后添加第二个循环(您可以对循环变量再次使用
a
),使用shtA.Cells(a,okcall).Value=
Yes!第二个循环成功了。我想要值“1”。这是我添加的:对于a=1+1到lastRow shtA.Cells(a,okcall).Value=1下一个a