我一直在写了几个星期的代码,它用来工作,它了2个小时通过49个工作表中我比较,但由于某种原因它来编译现在只是说没有回应。我真的想尝试切换使用数组,以便如果我能够再次使用它,它会快得多。然而,即使在阅读了大量有关数组的帖子之后,我也无法想出办法,除了知道我需要使用多维数组并且具有不同的行大小之外。任何人都可以提供任何建议吗?提前致谢!使用数组多个工作簿和工作表之间进行比较和共享数据
更多信息,代码看什么是E列,如果在E列别的东西与它匹配采用的值列牛逼通X,并将其放置在该行牛逼通X。如果它们的t通过x是空的,它也为行e着色,或者如果发现它不应该被着色,则使它再次变成白色。
Sub FindPart_FullWorkbooks()
'If searching multiple worksheets & workbooks
Dim PartNumber As String
Dim Found1 As Integer
Dim Found2 As Boolean
Dim Found3 As Boolean
Dim Found4 As Boolean
Dim Found5 As Boolean
Dim Found6 As Boolean
Dim Found7 As Boolean
Dim Found8 As Boolean
Dim Found9 As Boolean
Dim Found10 As Boolean
Dim Found11 As Boolean
Dim Found12 As Boolean
Dim EOS As String
Dim EOSL As String
Dim EOL As String
Dim Replace As String
Dim AddInfo As String
Dim n As Long
Dim m As Long
Dim LastRow As Long
Dim WS As Worksheet
Dim WS2 As Worksheet
Dim WB As Workbook
Dim WB2 As Workbook
For Each WB In Workbooks
For Each WS In WB.Worksheets
With WS
LastRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
End With
For m = 1 To LastRow
PartNumber = WB.Sheets(WS.Name).Cells(m, 5).Value
EOS = WB.Sheets(WS.Name).Cells(m, 20).Value
EOSL = WB.Sheets(WS.Name).Cells(m, 21).Value
EOL = WB.Sheets(WS.Name).Cells(m, 22).Value
Replace = WB.Sheets(WS.Name).Cells(m, 23).Value
AddInfo = WB.Sheets(WS.Name).Cells(m, 24).Value
Found2 = IsEmpty(WB.Sheets(WS.Name).Cells(m, 5).Value)
Found4 = IsEmpty(WB.Sheets(WS.Name).Cells(m, 20).Value)
Found5 = IsEmpty(WB.Sheets(WS.Name).Cells(m, 21).Value)
Found6 = IsEmpty(WB.Sheets(WS.Name).Cells(m, 22).Value)
Found7 = IsEmpty(WB.Sheets(WS.Name).Cells(m, 23).Value)
Found8 = IsEmpty(WB.Sheets(WS.Name).Cells(m, 24).Value)
If Found2 = True Then
GoTo NextIndex
Else
For Each WB2 In Workbooks
For Each WS2 In WB2.Worksheets
For n = 1 To LastRow
Found1 = InStr(WB2.Sheets(WS2.Name).Cells(n, 5).Value, PartNumber)
Found3 = IsEmpty(WB2.Sheets(WS2.Name).Cells(n, 20).Value)
Found9 = IsEmpty(WB2.Sheets(WS2.Name).Cells(n, 21).Value)
Found10 = IsEmpty(WB2.Sheets(WS2.Name).Cells(n, 22).Value)
Found11 = IsEmpty(WB2.Sheets(WS2.Name).Cells(n, 23).Value)
Found12 = IsEmpty(WB2.Sheets(WS2.Name).Cells(n, 24).Value)
If Found3 = True And Found9 = True And Found10 = True And Found11 = True And Found12 = True Then
If Found1 = 1 Then
WB2.Sheets(WS2.Name).Cells(n, 20).Value = EOS
WB2.Sheets(WS2.Name).Cells(n, 21).Value = EOSL
WB2.Sheets(WS2.Name).Cells(n, 22).Value = EOL
WB2.Sheets(WS2.Name).Cells(n, 23).Value = Replace
WB2.Sheets(WS2.Name).Cells(n, 24).Value = AddInfo
End If
End If
Next n
If Found4 = True And Found5 = True And Found6 = True And Found7 = True And Found8 = True Then
WB.Sheets(WS.Name).Cells(m, 5).Interior.Color = RGB(255, 0, 255)
ElseIf WB.Sheets(WS.Name).Cells(m, 5).Interior.Color = RGB(255, 0, 255) Then
WB.Sheets(WS.Name).Cells(m, 5).Interior.Color = RGB(255, 255, 255)
End If
'MsgBox (WB2.Name & " " & WS2.Name)
Next WS2
Next WB2
End If
'MsgBox (m)
NextIndex:
Next m
'MsgBox (WB.Name & " " & WS.Name)
Next WS
Next WB
End Sub
很抱歉,但澄清 - 这是否工作,只是需要大量的时间?如果是这样,你可能想在[CodeReview](https://codereview.stackexchange.com/)上提问。 – BruceWayne
它过去只是需要很多时间,但现在它冻结excel,我很好奇,如果有人可能知道如何将数组集成到它,以便它可以更好地工作。 – FrenchP