Converge 2 data centers with VBA

evenyougreg

New Member
Joined
Oct 1, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi!

I've had great success in the past here with VBA macros so I thought I would try my luck again. I pasted some mini sheets as an example, hopefully I did it correctly...

I need to converge 2 spreadsheet given the following scenario:

Spreadsheet 1 entitled "total_siteA.xlsx" with a sheet called "listA" has a long list of network devices,

row 1 are the headers "hostname,operating system,location" and the list starts on line 2. And it goes on and on for about 4000 rows.

Spreadsheet 2 entitled "total_siteB.xlsx" with a sheet called "listB" has the same sort of setup,

same row 1 headers "hostname,operating system,location" and the list starts on line 2 for about 2000 rows roughly.

If there is a hostname match when comparing siteB to siteA, then do nothing and move on,

If siteB has a hostname that is not present on siteA, then copy over/insert the values as a new row and move on.

Simply put, siteB has stuff that siteA has, and I don't care about those, but if B has something new then copy/insert it over to A along with the values.

Hopefully that makes sense, and thanks in advance!!

total_siteA.xlsx
ABC
1hostnameoperating systemlocation
2l-ubu1Ubuntu Linux (64-bit)vcenter1
3m-win1Microsoft Windows Server 2016 (64-bit)vcenter2
4l-ubu2Ubuntu Linux (64-bit)vcenter1
5l-rhel1RedHat (64-bit)vcenter1
6l-ubu3Ubuntu Linux (64-bit)vcenter1
7m-win2Microsoft Windows Server 2016 (64-bit)vcenter2
8l-ubu4Ubuntu Linux (64-bit)vcenter2
9m-win3Microsoft Windows Server 2016 (64-bit)vcenter2
10m-win4Microsoft Windows Server 2012 (64-bit)vcenter2
11l-rhel2RedHat (64-bit)vcenter2
12l-rhel3RedHat (64-bit)vcenter2
13m-win5Microsoft Windows Server 2016 (64-bit)vcenter2
14m-win6Microsoft Windows Server 2016 (64-bit)vcenter2
15l-ubu5Ubuntu Linux (64-bit)vcenter1
16m-win7Microsoft Windows Server 2016 (64-bit)vcenter1
17l-rhel4RedHat (64-bit)vcenter1
18m-win8Microsoft Windows Server 2016 (64-bit)vcenter1
19l-ubu6Ubuntu Linux (64-bit)vcenter1
20l-ubu7Ubuntu Linux (64-bit)vcenter1
21m-win9Microsoft Windows Server 2019 (64-bit)vcenter1
22m-win10Microsoft Windows Server 2019 (64-bit)vcenter2
23l-ubu8Ubuntu Linux (64-bit)vcenter2
24m-win11Microsoft Windows Server 2016 (64-bit)vcenter2
25l-ubu9Ubuntu Linux (64-bit)vcenter2
26m-win12Microsoft Windows Server 2012 (64-bit)vcenter1
27l-rhel5RedHat (64-bit)vcenter1
28l-ubu10Ubuntu Linux (64-bit)vcenter2
listA


total_siteB.xlsx
ABC
1hostnameoperating systemlocation
2l-suse1Suse 12 (64-bit)nutanix
3l-suse2Suse 12 (64-bit)nutanix
4l-suse3Suse 12 (64-bit)nutanix
5l-rhel2RedHat (64-bit)nutanix
6l-ubu9Ubuntu Linux (64-bit)nutanix
7l-suse4Suse 12 (64-bit)nutanix
8l-suse5Suse 12 (64-bit)nutanix
9l-suse6Suse 12 (64-bit)nutanix
10l-ubu10Ubuntu Linux (64-bit)nutanix
11m-win5Microsoft Windows Server 2016 (64-bit)nutanix
listB
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try the following macro. You can put it in a third book. The books with the lists must be open.

VBA Code:
Sub checklist()
  Dim dic As Object
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim i As Long, lr As Long
  Dim c As Range, rng As Range
  
  Set sh1 = Workbooks("total_siteA.xlsx").Sheets("listA")
  Set sh2 = Workbooks("total_siteB.xlsx").Sheets("listB")
  Set dic = CreateObject("Scripting.Dictionary")
  
  lr = sh1.Range("A" & Rows.Count).End(3).Row
  For Each c In sh1.Range("A2", sh1.Range("A" & lr))
    dic(c.Value) = Empty
  Next
  
  For Each c In sh2.Range("A2", sh2.Range("A" & Rows.Count).End(3))
    If Not dic.exists(c.Value) Then
      If rng Is Nothing Then Set rng = c Else Set rng = Union(rng, c)
    End If
  Next
  If Not rng Is Nothing Then rng.EntireRow.Copy sh1.Range("A" & lr + 1)
End Sub
 
Upvote 0
Solution
@DanteAmor would you be able to help with 1 more? Not sure if I should open up a new thread or not?

In this example file, sheet1 is called List and sheet 2 is called VMs.

If there is a "Hostname" match between the 2 sheets, I would like to copy the "OS" cell and the "Env" cell over from "VMs" to the "List" sheet. If no match is found then it would be cool if something like "not found" was to fill the empty cell.

example.xlsx
ABCDEF
1HostnameVM/PhysicalPower StateOSLocationEnv
2l-centtest01VMonWest
3l-ubu01VMonEast
4l-ubu02VMonWest
5l-webapp01VMonEast
6l-webapp02VMonEast
7m-iisapp01PhysicalonWest
8m-iisapp02PhysicalonEast
9m-poc01VMonEast
10m-poc02VMonWest
11m-sqldb01PhysicalonWest
12m-dsc01VMonEast
13m-dsc02VMonWest
List


example.xlsx
ABC
1HostnameOSEnv
2l-centtest01CentOS 7prod
3l-ubu01Ubuntu 20.04prod
4l-ubu02Ubuntu 20.04test
5l-webapp01RHEL 7prod
6l-webapp02RHEL 7prod
7m-iisapp01Windows-2012ServerR2prod
8m-iisapp02Windows-2012ServerR2prod
9m-poc01Windows-2019Servertest
10m-poc02Windows-2019Servertest
11m-sqldb01Windows-2016Serverprod
12m-sqldbtestWindows-2016Servertest
VMs
 
Upvote 0
The macro is different, you must create a new thread.
 
Upvote 0
I posted a new thread, if you're able to assist I appreciate it, if not thanks for your help anyhow.
 
Upvote 0

Forum statistics

Threads
1,223,670
Messages
6,173,707
Members
452,528
Latest member
ThomasE

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