Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare two spreadsheets

Status
Not open for further replies.

padinka

Programmer
Jul 17, 2000
128
US
I have two spreadsheets. Servers and Application.

I need to look at a column called IP in the server speadsheet and see if the IP has a Match in the Application spreadsheet's IP column. If so, move to the next row.

If not, then I need to look at a different column of the same row called HostName and see if there is a match on HostName in the Application speadsheet's HostName Column.
If so, move on to the next row.

If it matches neither IP or HostName, then I need to output the whole line from Server to a new spreadsheet.

Someone feel like attempting this for me?


Trisha
padinka@yahoo.com
 
Hi,

Something like this ought to work...
Code:
Sub LookItUp()
    Dim wsServ As Worksheet, wsAppl As Worksheet, wsNew As Worksheet
    Set wsServ = Worksheets("Servers")
    Set wsAppl = Worksheets("Applications")
    Set wsNew = Worksheets.Add
    With wsServ
        For Each r In .[IP]
            ptr = Application.Match(r.Value, wsAppl.[IP], 0)
            If IsError(ptr) Then
                ptr = Application.Match(r.Value, wsAppl.[HostName], 0)
                If IsError(ptr) Then
                    r.EntireRow.Copy _
                    distination:=wsNew.Cells(wsNew.Cells(1, 1).CurrentRegion.Rows.Count + 1, 1).Value
                End If
            End If
        Next
    End With
    Set wsServ = Nothing
    Set wsAppl = Nothing
    Set wsNew = Nothing
End Sub
:)

Skip,
Skip@TheOfficeExperts.com
 
oops

Destination

Sub LookItUp()
Dim wsServ As Worksheet, wsAppl As Worksheet, wsNew As Worksheet
Set wsServ = Worksheets("Servers")
Set wsAppl = Worksheets("Applications")
Set wsNew = Worksheets.Add
With wsServ
For Each r In .[IP]
ptr = Application.Match(r.Value, wsAppl.[IP], 0)
If IsError(ptr) Then
ptr = Application.Match(r.Value, wsAppl.[HostName], 0)
If IsError(ptr) Then
r.EntireRow.Copy _
Destination:=wsNew.Cells(wsNew.Cells(1, 1).CurrentRegion.Rows.Count + 1, 1).Value
End If
End If
Next
End With
Set wsServ = Nothing
Set wsAppl = Nothing
Set wsNew = Nothing
End Sub


sorry

Skip,
Skip@TheOfficeExperts.com
 
I'm getting a type mismatch error at:

For Each r In .[IP]



Trisha
padinka@yahoo.com
 
Hi,

2 things...
1. name you ranges using menu item Insert/Name/Create/Create names in top row.
2. remove .Value from the Destination
Code:
Sub LookItUp()
    Dim wsServ As Worksheet, wsAppl As Worksheet, wsNew As Worksheet
    Set wsServ = Worksheets("Servers")
    Set wsAppl = Worksheets("Applications")
    Set wsNew = Worksheets.Add
    With wsServ
        For Each r In .[IP]
            ptr = Application.Match(r.Value, wsAppl.[IP], 0)
            If IsError(ptr) Then
                ptr = Application.Match(r.Value, wsAppl.[HostName], 0)
                If IsError(ptr) Then
                    r.EntireRow.Copy _
                    Destination:=wsNew.Cells(wsNew.Cells(1, 1).CurrentRegion.Rows.Count + 1, 1)
                End If
            End If
        Next
    End With
    Set wsServ = Nothing
    Set wsAppl = Nothing
    Set wsNew = Nothing
End Sub


Skip,
Skip@TheOfficeExperts.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top