0

因此,我使用以下代码根据表列中的值做出一系列决策。我已经获取了包含在变体数组中做出决定的值的每个表列。然后使用 for 和 while 循环的组合在 ans() 变体数组中分配决策。

问题是,每次我运行宏时,我的 Excel 都会挂起。我尝试了添加自动计算和禁用事件和屏幕更新的常用方法。但这对这件事没有任何帮助。我也尝试过简化我的代码,但这大约是我可以包含的尽可能多的简化,同时仍能实现我想要的代码。有人可以告诉我我还能做些什么来让这个运行吗?

Dim sh As Worksheet
Set sh = Sheets("LOGIC")
Dim t As ListObject
Set t = sh.ListObjects("Table8")
n = t.ListRows.Count

Dim rel() As Variant
rel = t.ListColumns(61).DataBodyRange.Value

Dim dc() As Variant
dc = t.ListColumns(62).DataBodyRange.Value

Dim t_req() As Variant
t_req = t.ListColumns(63).DataBodyRange.Value

Dim sc_req() As Variant
sc_req = t.ListColumns(64).DataBodyRange.Value

Dim x_req() As Variant
x_req = t.ListColumns(65).DataBodyRange.Value

Dim bo() As Variant
bo = t.ListColumns(69).DataBodyRange.Value

Dim ans() As Variant
ans = t.ListColumns(70).DataBodyRange.Value

Dim reqkind() As Variant
reqkind = t.ListColumns(2).DataBodyRange.Value

 For i = 2 To n Step 1
  If rel(i, 1) = 0 Or ans(i, 1) <> 0 Then
   GoTo Nexti
  ElseIf ans(i, 1) = 0 And rel(i, 1) = 1 Then
   While t_req(i, 1) > 0
    For j = i To n - 1
     If dc(i, 1) > 0 Then
      If reqkind(i, 1) = "" Then
       ans(i, 1) = "YES"
       t_req(i, 1) = t_req(i, 1) - 1
       sc_req(i, 1) = sc_req(i, 1) - 1
      ElseIf sc_req(i, 1) <= 0 Then
       ans(i, 1) = "YES"
       t_req(i, 1) = t_req(i, 1) - 1
       x_req(i, 1) = x_req(i, 1) - 1
      Else: GoTo Nextj
      End If
     ElseIf reqkind(i, 1) = "" Then
      If bo(i, 1) > 0 Then
       ans(i, 1) = "YES"
       t_req(i, 1) = t_req(i, 1) - 1
       bo(i, 1) = bo(i, 1) - 1
      Else
       ans(i, 1) = "NO"
       t_req(i, 1) = t_req(i, 1) - 1
      End If
     Else
      ans(i, 1) = "NO"
      t_req(i, 1) = t_req(i, 1) - 1
     End If
Nextj:
    Next j
    Wend
  End If
Nexti:
  Next i```
4

0 回答 0