Loop and update from different workbooks

twckfa16

New Member
Joined
Dec 17, 2012
Messages
31
Hello -

I have a problem where I need to loop through 2 workbooks, determine if there are the same amount of entries for each Name, and
update one column if need be.

Attached are the two workbooks - the idea is to update what I highlighted in red in the _update file and say that BBB has more entries
in the _update file.

Here is a sample of the code :

Can anyone tell me if I am headed in the right direction?

Code:
Sub go()

Dim wb1 As Workbook
Dim wb2 As Workbook
Dim rng1 As Range
Dim rng2 As Range
Dim nam, group, color, number, typ As Byte
Dim done As String
Dim last1 As Long
Dim last2 As Long

done = "done"


For Each wb1 In Workbooks
   If wb1.name Like "file_master*" Then
      wb1.Activate
   Sheets("Sheet1").Activate
   Set rng1 = wb1.Worksheets("Sheet1").Range("A:A")
   Else
   End If
Next wb1
  
For Each wb2 In Workbooks
   If wb2.name Like "file_update*" Then
      wb2.Activate
   Sheets("Sheet1").Activate
   Set rng2 = wb2.Worksheets("Sheet1").Range("A:A")
   Else
   End If
Next wb2

    last1 = rng1.End(xlDown).Row
    last2 = rng2.End(xlDown).Row
    
    For i = 1 To lastrowone
        If cel1.Value = cel2.Value Then
           nam = True
           If cel1.Offset(0, 1) = cel2.Offset(0, 1) Then
              group = True
              If cel1.Offset(0, 2) = cel2.Offset(0, 2) Then
                 color = True
                 If cel1.Offset(0, 3) = cel2.Offset(0, 3) Then
                    number = True
                    If cel1.Offset(0, 4) = cel2.Offset(0, 4) Then
                       typ = True
                    Else
                       cel2.Offset(0, 4) = cel1.Offset(0, 4)
                       cel2.Offset(0, 7) = done
                    End If
                 Else
                 End If
              Else
              End If
           Else
           End If
        Else
        End If
    Next i

End Sub

[CODE=vba]

{/CODE]
 

Attachments

  • file_master.jpg
    file_master.jpg
    98.2 KB · Views: 11
  • file_update.jpg
    file_update.jpg
    115.2 KB · Views: 11

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,215,093
Messages
6,123,068
Members
449,091
Latest member
remmuS24

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