I have been working on comparing two columns in one workbook and comparing it with two columns in another "workbook2". My code runs fine but I have found a glitch.
Because I am working with Ip addresses in one of the columns if the ip address is 10.10.0.1 and another ip address is 10.10.0.10, the results for the ip address 10.10.0.1 do not get written to Column B. I will give an example below
Row two column B should have an entry for the slave but it does not show up. My criteria looks at column C and D in order to make it a unique and each unique pairing has a name to it
I've noticed in the FInd feature when I enter 10.10.0.1, it will give me a list for all addresses that start with 10.10.0.1, such as 10.10.0.11, 10.10.0.17, etc.
I have thousands of entries and searching for each ip that may be having this issue will take a long time. Is there anyway for the code to make an exact match?
Because I am working with Ip addresses in one of the columns if the ip address is 10.10.0.1 and another ip address is 10.10.0.10, the results for the ip address 10.10.0.1 do not get written to Column B. I will give an example below
Host | Name | Ip address | Serial Number |
sfdgsthgfh | Master | 10.10.0.1 | SerialNumber1 |
sfdgsthgfh | 10.10.0.1 | SerialNumber2 | |
aghjutre | Master | 10.10.0.10 | SerialNumber3 |
aghjutre | Slave | 10.10.0.10 | SerialNumber4 |
Row two column B should have an entry for the slave but it does not show up. My criteria looks at column C and D in order to make it a unique and each unique pairing has a name to it
I've noticed in the FInd feature when I enter 10.10.0.1, it will give me a list for all addresses that start with 10.10.0.1, such as 10.10.0.11, 10.10.0.17, etc.
I have thousands of entries and searching for each ip that may be having this issue will take a long time. Is there anyway for the code to make an exact match?
VBA Code:
Sub InsertDeviceName_NewBook()
Dim w1 As Worksheet, w2 As Worksheet, wsnew As Worksheet
Dim wbnew As Workbook
Dim c As Range, FR As Variant
Dim d As Range
Dim e As Range 'rng1 As Range, rng2 As Range
Dim lr1 As Long, lr2 As Long
Dim x As Long, i As Long, lr As Long
Dim rng1 As Variant, rng2 As Variant
Dim vals()
Application.ScreenUpdating = False
Set w2 = Workbooks("book2.xlsx").ActiveSheet
Set w1 = Workbooks("book1.xlsx").ActiveSheet
w1.Range("B:D").Copy
Set wbnew = Workbooks.Add
Columns("A:A").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Name = w1.Name
Set wsnew = wbnew.ActiveSheet
lr1 = wsnew.Cells(Rows.count, 1).End(xlUp).Row
lr2 = w2.Cells(Rows.count, 1).End(xlUp).Row
wsnew.Sort.SortFields.Add2 Key:=Range("B1"), _
SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With wsnew.Sort
.SetRange Range("A1:C" & lr1)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Columns("B:B").Insert Shift:=xlToRight, _
CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").Select
ActiveCell.FormulaR1C1 = "Device Name"
rng1 = wsnew.Range("C2", wsnew.Range("D" & wsnew.Cells(Rows.count, 1).End(xlUp).Row)).Value
rng2 = w2.Range("B2", w2.Range("D" & w2.Cells(Rows.count, 1).End(xlUp).Row)).Value
ReDim vals(1 To UBound(rng1, 1), 1)
For x = 1 To UBound(rng1, 1)
For i = 1 To UBound(rng2)
If rng1(x, 1) = rng2(i, 2) Then
If rng1(x, 2) = rng2(i, 3) Then
vals(x, 0) = rng2(i, 1)
GoTo Nextone
End If
End If
Next i
Nextone:
Next x
wsnew.Range("B2").Resize(UBound(vals, 1), 1).Value = vals
Application.ScreenUpdating = True
End Sub