我已经尝试解决这个问题好几个星期了。我有一个包含用户表单的模板。此用户表单选择当月报告和上月报告并在当月报告中运行 vlookup。它在 B 列中运行 vlookup。问题是,代码运行 vlookup 并且不会停止,我需要它在遇到 C 列中的空白单元格时立即停止。这是代码。我在这里急需帮助。谢谢!
Private Sub CommandButton1_Click()
Dim str1 As String
Dim str2 As String
Dim i As Integer
Application.ScreenUpdating = False
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
str1 = ListBox1.List(i)
End If
Next i
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i) = True Then
str2 = ListBox2.List(i)
End If
Next i
Workbooks(str1).Activate
Sheets(1).Activate
Range("B1").Select
i = 0
Do Until ActiveCell.Offset(i, 0).Value = "Category"
i = i + 1
Loop
Range("B1").Offset(i, 0).Select
With Range(ActiveCell.Offset(1), Cells(ActiveSheet.UsedRange.Rows.Count, 2))
.Formula = "=VLOOKUP(C" & ActiveCell.Offset(1).Row & ",'[" & str2 & "]Sheet1'!$A$4:$B$200,2,FALSE)"
End With
Application.ScreenUpdating = True
End Sub