• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Input Message depends on the text in one cell left to the active cell

Kennysan

New Member
Hello!
I am new to VBA and I am hoping if anyone could please help me finding a solution.

I have a table like the below, calling it 'INSTRUCTION' table in 'MASTER' sheet. My goal is show an input message when a cell is selected.
But the contents of the message depends on the text in one cell left to the active cell.
75803

I have another sheet called 'LOV', which has a table called 'NAME_JOB'.
75804

If in MASTER sheet, C2 is selected, then perform VLOOKUP of B2 from NAME_JOB table in LOV sheet, if the value exists then return the value in the input message.
If the value does not exist, simply do nothing.

Is this something achievable with VBA?

Thank you in advance!
Kenny
 

Attachments

  • VLOOKUP in Input Message.xlsx
    10.7 KB · Views: 2
Right-click the sheet tab MASTER and choose View Code, then where the cursor is in the Visual Basic Editor, paste this in:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count = 1 Then
  If Not Intersect(Target, Range("Table2[INSTRUCTION]")) Is Nothing Then
    msg = Application.VLookup(Target.Offset(, -1).Value, Sheets("LOV").Range("Table1"), 2, False)
    If IsError(msg) Then Target.Validation.InputMessage = "" Else Target.Validation.InputMessage = msg
  End If
End If
End Sub
It relies on there already being Data Validation present in those cells. (If there isn't data validation in there already, the code can be tweaked to add it.)
Make sure there isn't another Sub Worksheet_SelectionChange(ByVal Target As Range) in the same code module.

ps. The table names in your sample file weren't named as you described but just Table1 and Table2, so try this in your sample file first to confirm it works then tweak the code to match your actual table names in your working file.
 
Last edited:
Back
Top