instanceoftime
Board Regular
- Joined
- Mar 23, 2011
- Messages
- 103
Spreadsheet A (Items) and Spreadsheet incoming
I would like help figuring out code that will allow me to choose which file to open and compare.
(open worksheet would be a master inventory list and I would open an incoming inventory list and search it for non-matching products (NEW) to the master sheet)
What I am comparing is cell (i,A), (i,C) of the incoming spreadsheet to any row in the masterlist and if it isn't on the masterlist then add the whole row (A through F)
below is a similar search within the sheet but for only 1 cell and from a user textbox.
for example below is Item worksheet
John W Smith 509555555 99202
Jim H Smith 095554444 99203
John L Henry 509554333 99204
so for example below is incoming worksheet
Sandy j Brown 5555555 99201
Jean Y Simmon 4444444 99206
Jim H Smith 5095555 99202
Item worksheet would open up Incoming worksheet and "grab" Sandy and Brown and search itself to see if that data is already there and if not write the whole row to itself (Item worksheet) (it would find Jim Smith and bypass it)
I would like help figuring out code that will allow me to choose which file to open and compare.
(open worksheet would be a master inventory list and I would open an incoming inventory list and search it for non-matching products (NEW) to the master sheet)
What I am comparing is cell (i,A), (i,C) of the incoming spreadsheet to any row in the masterlist and if it isn't on the masterlist then add the whole row (A through F)
below is a similar search within the sheet but for only 1 cell and from a user textbox.
Code:
Sub SearchUPC()
Dim NotFound As Integer
Dim arr As Variant
Dim I As Long
Dim str1 As String, str2 As String, str3 As String, str4 As String, str5 As String, str6 As String
NotFound = 0
ActiveWorkbook.Sheets("Items").Activate
UPCNumber = txtbxUPCNumber.Text
With ActiveSheet
arr = .Range("A1:H" & .Cells(.Rows.Count, "G").End(xlUp).Row)
End With
For I = 1 To UBound(arr)
If arr(I, 7) = UPCNumber Then
str1 = IIf(str1 = "", arr(I, 1), str1 & "|" & arr(I, 1))
str2 = IIf(str2 = "", arr(I, 2), str2 & "|" & arr(I, 2))
str3 = IIf(str3 = "", arr(I, 3), str3 & "|" & arr(I, 3))
str4 = IIf(str4 = "", arr(I, 4), str4 & "|" & arr(I, 4))
str5 = IIf(str5 = "", arr(I, 7), str5 & "|" & arr(I, 7))
str6 = IIf(str6 = "", arr(I, 8), str6 & "|" & arr(I, 8))
End If
Next
If str1 = "" Then
'not found
Else
'found
End If
End Sub
for example below is Item worksheet
John W Smith 509555555 99202
Jim H Smith 095554444 99203
John L Henry 509554333 99204
so for example below is incoming worksheet
Sandy j Brown 5555555 99201
Jean Y Simmon 4444444 99206
Jim H Smith 5095555 99202
Item worksheet would open up Incoming worksheet and "grab" Sandy and Brown and search itself to see if that data is already there and if not write the whole row to itself (Item worksheet) (it would find Jim Smith and bypass it)
Last edited: