我目前在Microsoft Excel中使用以下宏。然而,无论何时我运行它,应用程序都会冻结很长一段时间。不太清楚是哪里的问题可能是在我下面的代码:运行特定的宏会冻结Microsoft Excel
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Cells.Select
Selection.RowHeight = 20.25
Columns("E:E").Insert
Columns("E:E").ColumnWidth = 7
Columns("J:J").Insert
Columns("J:J").ColumnWidth = 7
Columns("L:L").Insert
Columns("L:L").ColumnWidth = 7
Columns("M:M").Insert
Columns("M:M").ColumnWidth = 7
Columns("M:M").Insert
Columns("M:M").ColumnWidth = 7
Columns("L:L").Copy
Range("J1").PasteSpecial xlPasteFormats
Application.CutCopyMode = flase
For Each cel In Range("F:F")
If cel.Font.Underline = xlUnderlineStyleSingle Then
cel.Value = "x" & cel.Value
End If
Next
For Each cel In Range("H:H")
If cel.Font.Underline = xlUnderlineStyleSingle Then
cel.Value = "x" & cel.Value
End If
Next
Application.ScreenUpdating = False
a = Cells(Rows.Count, "C").End(xlUp).Row
For b = 1 To a
If IsNumeric(Cells(b, "C").Value) Then
st = Cells(b, "G").Value
t1 = Cells(b, "F")
t2 = Cells(b, "H")
v1 = 1.72
v2 = 2.1
v3 = 1.9
v4 = 1.8
v5 = 2
If InStr(st, "+10") > 0 And Left(Cells(b, "F"), 1) = "x" Then
Cells(b, "E") = v1
Cells(b, "J") = v2
ElseIf InStr(st, "-10") > 0 And Left(Cells(b, "F"), 1) = "x" Then
Cells(b, "E") = v3
Cells(b, "J") = v3
ElseIf InStr(st, "-5") > 0 And Left(Cells(b, "F"), 1) = "x" Then
Cells(b, "E") = v5
Cells(b, "J") = v4
ElseIf Left(Cells(b, "F"), 1) = "x" Then
Cells(b, "E") = v4
Cells(b, "J") = v5
ElseIf InStr(st, "+10") > 0 And Left(Cells(b, "H"), 1) = "x" Then
Cells(b, "J") = v1
Cells(b, "E") = v2
ElseIf InStr(st, "-10") > 0 And Left(Cells(b, "H"), 1) = "x" Then
Cells(b, "J") = v3
Cells(b, "E") = v3
ElseIf InStr(st, "-5") > 0 And Left(Cells(b, "H"), 1) = "x" Then
Cells(b, "J") = v5
Cells(b, "E") = v4
ElseIf Left(Cells(b, "H"), 1) = "x" Then
Cells(b, "J") = v4
Cells(b, "E") = v5
ElseIf InStr(st, "-10") > 0 Then
Cells(b, "J") = v3
Cells(b, "E") = v3
Else
Cells(b, "E") = 0
Cells(b, "J") = 0
End If
End If
Next
Application.ScreenUpdating = True
End Sub
我相信问题可能与RAM或下面的下面的代码片段,我已经厌倦了修改,但还没有任何运气:
For Each cel In Range("F:F")
If cel.Font.Underline = xlUnderlineStyleSingle Then
cel.Value = "x" & cel.Value
End If
Next
For Each cel In Range("H:H")
If cel.Font.Underline = xlUnderlineStyleSingle Then
cel.Value = "x" & cel.Value
End If
Next
使用范围'F:F'表示它适用于整个'F'列。你是否在整个列中填充了每一行“F”?如果不是,请缩小范围以仅包含包含数据的行。同样的事情适用于'H:H'。 –
是的,不要为范围内的每个cel(“H:H”)做',因为它会检查*整列*。找到最后一行(类似Dim'LastRow为Integer // lastRow = cells(rows.count,1).End(xlUp).Row',并且执行Range(“H1:H”&lastRow)''等等。 (只需更改'cells()'中的'1'以匹配要检查的数据的列) – BruceWayne
好的,我会尽力感谢 –