jonnycantprogram
New Member
- Joined
- Jul 23, 2014
- Messages
- 5
Hey guys, I'm a bit new to this but am starting to get the hang of it but could use some help. I have a large data file with several different worksheets. In one cell I have a large set of individual numbers (i.e in the cell there is "123456 234234 939829") This value is my 'sample' number. The same sample could be in multiple rows on one sheet and could also be on other sheets. I am trying to find the sample in a column (on some sheets its column "Q", other sheets it could be different columns, but that column is fixed per sheet) and then copy the information on the same row in columns A & B and copy it to my target sheet. Then the next place the sample appears copy that info to the next row of my target sheet. So far I am stuck getting it to find the multiple values on one sheet. My code is below. I hope I have put everything in the right format for you. First time using the forums. Any and all help is greatly appreciated.
Code:
Sub Samplesearch()
Dim sample As String
Dim x As Integer
Dim y As Integer
Dim lr As Long
Dim lsr As Long
'clear sample lookup sheet
Worksheets("Sample Lookup").Activate
Range("A:B").ClearContents
'Prompt Sample Lookup
sample = InputBox("What sample are you looking for?", "Sample Search")
If sample = "" Then
GoTo EndLookup
End If
lr = Sheets("Urine").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Urine").Activate
With Cells
.Find(sample).Select
ActiveCell.Offset(0, -16).Copy
Sheets("Sample Lookup").Activate
lsr = Sheets("Sample Lookup").Range("A" & Rows.Count).End(xlUp).Row
Cells(lsr, 1).PasteSpecial
Sheets("Urine").Select
ActiveCell.Offset(0, -15).Copy
Sheets("Sample Lookup").Activate
Cells(lsr, 2).PasteSpecial
Do
.FindNext.Select
ActiveCell.Offset(0, -16).Copy
Sheets("Sample Lookup").Activate
lsr = Sheets("Sample Lookup").Range("A" & Rows.Count).End(xlUp).Row
Cells(lsr, 1).PasteSpecial
Sheets("Urine").Select
ActiveCell.Offset(0, -15).Copy
Sheets("Sample Lookup").Activate
Loop
End With
' Next y
EndLookup:
End Sub