PDA

View Full Version : Search



oleg_v
12-22-2010, 07:15 AM
hi
i have this macro:
Public Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim nm As Range
On Error GoTo eh
If Not Intersect(Target, Range("A1:A10")) Is Nothing Then

Dim Found As Range, It
It = Target.Value
Set Found = Sheets("sheet3").Columns("g").Find(what:=It, LookIn:=xlValues, lookat:=xlWhole)
If Not Found Is Nothing Then
MsgBox It & " found in " & Found.Address(False, False), vbInformation
Else
MsgBox It & " not found.", vbExclamation
End If
End If
eh:
End Sub





ho can i display in the " MsgBox It & " found in " & Found.Address(False, False), vbInformation" the value in the differant column but in the same row with the foun value


thanks

Simon Lloyd
12-22-2010, 08:28 AM
If you want the found address in a column opposite the target then you can use:

Target.Offset(1,0).Value = Found.Address
other than that im not sure what you mean?

oleg_v
12-22-2010, 08:36 AM
hi
i need to display the containmet of the tatget column and one more column in the same msgbox

Simon Lloyd
12-22-2010, 11:27 AM
I don't understand, sorry!, do you mean something like this:
MsgBox It & " found in " & Found.Address(False, False) & " Next Column is " & _
Found.Offset(0,1).Column & " Address " & Found.Offset(0,1).Address , vbInformation So you get the idea on how to show another address or column or row related to the FOUND item.