Msg Box -VBA code

I have 2 different worksheets:

·         worksheet-1

·         worksheet-2

I want msgbox in worksheet-1 referring to values in worksheet-2.

For example:

In worksheet-1:

| A |

| B |

| C |

In worksheet-2:

| A | 10 | 5  | 6 | 4 |

| B | 5  | 4  | 2 | 1 |

| C | 5  | 10 | 5 | 6 |

When I give key on worksheet-1, it should refer to the values in worksheet-2 and show as a msgbox.

Msg box:

| A  |

| 10 |

| 5  |

| 6  |

| 4  |

 

 

The code I have so far is:

Sub Search()

    Msg = “CALL DETAILS” & vbCr

    For Each cell In Sheets(“sheet1”).Range(“B2:B” & Sheets(“sheet1”).Cells(Rows.Count, “B”).End(xlUp).Row)

        If LCase(cell.Value) = LCase(Selection.Value) Or InStr(1, LCase(cell.Value), _

            LCase(Selection.Value)) > 0 Then

                Msg = Msg & vbCr & cell.Offset(0, 1) & ” / “ & vbCr & cell.Offset(0, 2) & ” / “ & cell.Value

        End If

    Next

    i = MsgBox(Msg, vbInformation)

End Sub

 

By: Naresh

Leave a Reply

Your email address will not be published. Required fields are marked *