Helidragon
New Member
- Joined
- Jan 31, 2019
- Messages
- 13
Help Please, this code is taking to long to complete. I believe because of the two Loops, each loop contains 100 cells so it is looping through 10000 cells and taking about 6 mins to complete. My guess is there is another way to do this and not take so long. Any help would be appreciated.
Code:
Private Sub CommandButton1_Click()
Dim c, c2, SN, FLexBn, FlexNN As Range
Dim Flex As Workbook
Dim wks As Worksheets
Set SN = Worksheets((MonthName(Month(Range("Date")))))
Set RngAN = SN.Range("DLCAN11")
Set AN = Range("1:24").Find("Acct. No.", , , xlWhole, , , False, , False)
Set Flex = Workbooks.Open("c:\Flex 123\Monitored Line (Flex 123) Report.xlsx")
Set RLC = ThisWorkbook
For Each c In RngAN
If c.Value <> "" And c.Value <> "Days Past Due" Then
With Flex
For Each c2 In Worksheets("page1").Range("c4:c100")
If c2.Value = c.Value Then
c2.Interior.ColorIndex = 38
End If
Next c2
End With
End If
Next
For Each c2 In Flex.Worksheets("page1").Range("c4:c100")
With Flex
For Each c In RngAN
If c.Value = c2.Value And c.Value <> "Days Past Due" Then
If c.Offset(0, -1).Value <> c2.Offset(0, 1).Value Then
c.Offset(0, -1).Interior.ColorIndex = 38
c.Offset(0, -1).Value = c2.Offset(0, 1).Value
End If
If c.Offset(0, 2).Value <> c2.Offset(0, 5).Value Then
c.Offset(0, 2).Interior.ColorIndex = 38
c.Offset(0, 2).Value = c2.Offset(0, 5).Value
End If
If c.Offset(0, 8).Value <> c2.Offset(0, 6).Value Then
c.Offset(0, 8).Interior.ColorIndex = 38
c.Offset(0, 8).Value = c2.Offset(0, 6).Value
End If
If c.Offset(0, 7).Value <> c2.Offset(0, 7).Value Then
c.Offset(0, 7).Interior.ColorIndex = 38
c.Offset(0, 7).Value = c2.Offset(0, 7).Value
End If
If c.Offset(0, 6).Value <> c2.Offset(0, 8).Value Then
c.Offset(0, 6).Interior.ColorIndex = 38
c.Offset(0, 6).Value = c2.Offset(0, 8).Value
End If
End If
Next c
End With
Next
End Sub
Last edited by a moderator: