填充 ListBox 时,宏卡在 For Each 循环中

Macro stuck in For Each loop when populating ListBox

我有以下代码来填充列表框:

For Each cellValue In Sheet7.Range("A:A").Cells
    If cellValue.value = Get_ClientID(TextBox1.Text) Then
        equipmentName = Get_EquipmentName(Sheet7.Cells(cellValue.row, 2))
        numeroCalibracao = TextBox6.Text
        ultimacalibracao = TextBox5.Text
        ListBox1.AddItem equipmentName
        ListBox1.List(ListBox1.ListCount, 1) = numeroCalibracao
        ListBox1.List(ListBox1.ListCount, 2) = ultimacalibracao
    End If
Next

问题是当运行时,Excel变得没有响应,甚至连Ctrl + Break都无法跳出循环。它应该根据 Sheet 7 上匹配条目的数量填充列表框。我尝试用数字替换 ListBox1.Listcoun,但它仍然不起作用。我错过了什么?

信息:

如果需要更多信息,请告诉我,我会提供。

问题是你的主循环,你要遍历 A 列中的每一行。我建议你将范围设置为 "Range("A1:A" & LastRow),其中 LastRow 是你的最后一行,例如:

LastRow = Range("A:A").Find(what:="*", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).row

如果仍然没有响应,请在循环中添加 DoEvents