Speed up camparing two workbooks VBA

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:
Thank you everyone for the help. I started changing it but it will take me a few days to try each idea and work through the kinks of not knowing what I’m doing. ?
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,216,584
Messages
6,131,565
Members
449,655
Latest member
Anil K Sonawane

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top