Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default comparing serial #s against another sheet then only displaying only the matching items and all associated data

Hi All
I have been trying to work out how to take the serial numbers from,
say, worksheet1, compare those serial numbers to those taken from a
database in worksheet2. Then only displaying the matching serial
numbers and ALL associated data with that serial number from WS2, on
worksheet3.

I have a barcode reader which I use for auditing my equipment. It
collects the asset serial numbers and I would like to speed up the
comparison to the database.

I have some code, its says I have matches but its doesn't display the
results on worksheet3.

Any help and guidance would be greatly appreciated.

Thanks in advance



The code is as follows:-

Sub SearchandCopy()

' This macro is used to loop through a column - specfied by the
"ColumnVar" variable - of values, in "Sheet2". Searching for a
' matching value in any of the rest of Sheet2. If it finds a match it
copies the row to Sheet3, starting at column A to
' column number x specified by ".Cells(x, 5). Assuming row 3, would
copy cells A3:E3.

Dim reference_value As Variant
Dim lastrow_lookup As Long, x As Long, ColumnArray(100) As String, intI
As Integer, ColumnVar As String

For intI = 1 To 30
ColumnVar = "R" & intI
ColumnArray(intI) = ColumnVar
Debug.Print ColumnArray(intI)
Next

For intI = 1 To 30
With ThisWorkbook.Sheets("Sheet2")
reference_value = .Range(ColumnArray(intI))
lastrow_lookup = .Cells(Rows.Count, 1).End(xlUp).Row
Debug.Print reference_value
End With

For x = 1 To lastrow_lookup
If Sheets("Sheet2").Cells(x, 1) = reference_value Then
Debug.Print "match"
Sheets("Sheet2").Range(Sheets("Sheet2").Cells(x, 1),
Sheets("Sheet2").Cells(x, 9)).Copy
Sheets("Sheet3").Cells(Sheets("Sheet3").Cells(Rows .Count,
1).End(xlUp).Row + 1, 1)
End If
Next x
Next
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default comparing serial #s against another sheet then only displaying only the matching items and all associated data

Something like this is what you need. Taylor it to suit your specific
needs. If you need a hand just reply back.

Sub test()

Dim arrWK1(70) As Long
Dim arrWK2(70) As Long
Dim x As Integer, y As Integer, counter As Integer

counter = 1

For x = 1 To 70
arrWK1(x) = Sheet1.Cells(x, 1).Value
For y = 1 To 70
arrWK2(y) = Sheet2.Cells(y, 1).Value
If arrWK1(x) = arrWK2(y) Then
Sheet3.Cells(counter, 1).Value = arrWK1(x)
counter = counter + 1
End If
Next y
Next x

End Sub
wrote in message
oups.com...
Hi All
I have been trying to work out how to take the serial numbers from,
say, worksheet1, compare those serial numbers to those taken from a
database in worksheet2. Then only displaying the matching serial
numbers and ALL associated data with that serial number from WS2, on
worksheet3.

I have a barcode reader which I use for auditing my equipment. It
collects the asset serial numbers and I would like to speed up the
comparison to the database.

I have some code, its says I have matches but its doesn't display the
results on worksheet3.

Any help and guidance would be greatly appreciated.

Thanks in advance



The code is as follows:-

Sub SearchandCopy()

' This macro is used to loop through a column - specfied by the
"ColumnVar" variable - of values, in "Sheet2". Searching for a
' matching value in any of the rest of Sheet2. If it finds a match it
copies the row to Sheet3, starting at column A to
' column number x specified by ".Cells(x, 5). Assuming row 3, would
copy cells A3:E3.

Dim reference_value As Variant
Dim lastrow_lookup As Long, x As Long, ColumnArray(100) As String, intI
As Integer, ColumnVar As String

For intI = 1 To 30
ColumnVar = "R" & intI
ColumnArray(intI) = ColumnVar
Debug.Print ColumnArray(intI)
Next

For intI = 1 To 30
With ThisWorkbook.Sheets("Sheet2")
reference_value = .Range(ColumnArray(intI))
lastrow_lookup = .Cells(Rows.Count, 1).End(xlUp).Row
Debug.Print reference_value
End With

For x = 1 To lastrow_lookup
If Sheets("Sheet2").Cells(x, 1) = reference_value Then
Debug.Print "match"
Sheets("Sheet2").Range(Sheets("Sheet2").Cells(x, 1),
Sheets("Sheet2").Cells(x, 9)).Copy
Sheets("Sheet3").Cells(Sheets("Sheet3").Cells(Rows .Count,
1).End(xlUp).Row + 1, 1)
End If
Next x
Next
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
displaying missing data by comparing two sets Shu of AZ Excel Discussion (Misc queries) 0 April 16th 09 07:50 PM
Displaying items from a column list in another sheet? pieman3 Excel Worksheet Functions 18 April 7th 09 03:03 PM
Grouping a column of data and displaying the number of items grouped [email protected] Excel Worksheet Functions 2 April 16th 08 10:16 PM
Comparing Cells and Displaying Data Keith Brown Excel Worksheet Functions 1 February 9th 05 05:42 PM
Excel Vba - Comparing 2 ranges of data and displaying result in another worksheet wuming[_11_] Excel Programming 4 July 14th 04 07:44 AM


All times are GMT +1. The time now is 01:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"