Thread: Search
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Search

Can you answer these questions for us please?

1) Can your Sheet2 codes appear anywhere within the values in your Sheet1
cells, or will they always occur at the end of the values as your examples
show?

2) Are there any cases where a code can be embedded within a Sheet1 cell
value where you would not consider it a match? If so, can you describe how
you would know they shouldn't be considered a match?

3) Your codes are shown as being all numbers, so why are you applying the
UCase function to them and the cell values you are trying to match them with
in your If..Then test? Are your actual codes different than you showed us?
If so, can you describe the structure behind the for us?

--
Rick (MVP - Excel)


"fi.or.jp.de" wrote in message
...
Hi All,

I have 7 columns in sheet1 & in sheet2 i have 2 columns with some
data.

In sheet2 Col A
I have some codes like
001
125
4563

Same codes repeated in sheet 1 in any of the columns ( Col B to Col
G )

I need to match sheet2 col A data with sheet1 Col B to col G, if it
matches i need data available in sheet1 col A in sheet 2 col B

I am using this code.

For i = 2 to 50

For a = 2 To 100
Frst = UCase(sheets("Sheet2").Cells(i,
"A").Value)

with sheets("Sheet1")
If Frst = UCase(.Cells(a, "B").Value) Or _
Frst = UCase(.Cells(a, "C").Value) Or _
Frst = UCase(.Cells(a, "D").Value) Or _
Frst = UCase(.Cells(a, "E").Value) Or _
Frst = UCase(.Cells(a, "F").Value) Or _
Frst = UCase(.Cells(a, "G").Value) then

Temp = .Cells(a, "A")
res = res & "," & Temp

End If
end with
Next a
If res < "" Then
sheets("Sheet2").Cells(i, "B") = WorksheetFunction.Substitute
(res, ",", "", 1)
res = ""
next i


Above vba works fine, but I have some exceptions.

Some code in sheet1 is like W001 or F001 or L001 or T001
but in sheet2 has 001, so exact will not find this cases.

How can i modify my code, Even i thought about wild seraches
like "*" & Frst & "*" = "*" & UCase(sheets("Sheet1").Cells(a,
"D").Value) & "*"

But pulls out the results where the code say 123001 or ABCED001
etc....

Please help me !!