我正在尝试从主数据工作表中查找值,检查“条件1”是否为真,并使用VBA在项目访问工作表中使用标题为“SITE#1”的每一列填充“值”。
请注意,行数和列数将保持不变,因此我希望使用.UsedRange
来减少不必要的循环。
截图
代码
Private Sub CommandButton1_Click()
Set rng1 = Range("b3")
On Error Resume Next
Dim P_Row As Long
Dim P_Clm As Long
Table1 = Sheet2.Range("A:A") ' LOOKUP VALUE
Table2 = Sheet1.Range("A:B") ' Range of LOOKUP VECTOR
Dept_Row = Sheet2.Range(rng1.Address).Row ' CURRENT DUE FOR THE MONTH
Dept_Clm = Sheet2.Range(rng1.Address).Column
For Each cl In Table1
Sheet2.Cells(P_Row, P_Clm) = Application.WorksheetFunction.VLookup(cl, Table2, 2, False)
Dept_Row = P_Row + 1
Next cl
End Sub