Tootip with vlookup

simon_ives

New Member
Joined
Jul 12, 2014
Messages
9
Hi all.

I'm wondering if anyone can share a method to add a tooltip that displays the results of a vlookup?

For example, I have a large vehicle tracking spreadsheet with a variety of worksheets for collating monthly data on logbook page numbers, KMs travelled, private usage, missing KMs, etc. What I'd like to do is have a tooltip appear over certain cells on one worksheet that displays the vehicle's contact person's name, as pulled from the vehicle details worksheet.

At the moment we can either add a new row and include a vlookup, but this adds too much duplicate data as the information is present on another worksheet. Or we just navigate to the vehicle details worksheet and search for the vehicle via the rego number.

Thanks in advance.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I don't believe you can do it with a straight out comment....but, you could use VBA
Maybe something like this...you'll need to modiy cell references, etc

Code:
Sub MakeComment()
    With Worksheets(1).Range("A1").AddComment
        .Visible = True
        .Text "The Contact Person for This Vehicle is " & YOUR FORMULA
    End With
End Sub
 
Upvote 0
Thanks Michael, that's exactly the kind of thing I'm looking for.

Quick question though. For the VBA snippet reading: "Worksheets (1)" do I add the textual name of the worksheet in the parentheses?

Thanks again.
 
Upvote 0
You can either use the code number (1), etc
OR
Code:
Sub MakeComment()
    With Sheets("YOURSHEETNAME").Range("A1").AddComment
        .Visible = True
        .Text "The Contact Person for This Vehicle is " & YOUR FORMULA
    End With
End Sub
 
Upvote 0
Thanks!

I've added the following so far to test:

Code:
Sub MakeComment()
    With Worksheets("Logbook Tracking").Range("C6").AddComment
        .Visible = True
        .Text "The Contact Person for This Vehicle is "
    End With
End Sub

Where "Logbook Tracking" is the name of the worksheet, "C6" is the worksheet's cell where I'd like the comment to display, and I've ommitted the vlookup for testing so that I can ensure the remaining syntax is complete.

However, the above code does not result in displaying a comment in cell C6. Any ideas on how to move forward with this?

I've also tried "worksheets (2)" with no luck - the VBA Project has the worksheet's details as "Sheet2 (Logbook Tracking)"

Thanks again.
 
Upvote 0
Where are you putting the code....did you want it to fire automatically ??
If so, change it to a Workbook_Change event and paste the code into the Sheet module.
Do you want this work on more than one cell ??
 
Upvote 0
Thank you very much for the assistance.

I have tried the code both on the worksheet in the VBA project and the workbook in the VBA project.

I would like it to fire automatically. If it doesn't, what should the trigger be?

I need this to work on 69 cells in the same column (each of the 69 rows represents a different vehicle).

If I use a Workbook_Change, what would the correct syntax be for the comment addition?

The vlookup code to return the vehicle's contact is (Where "A6" varies across the 69 rows):

Code:
=VLOOKUP(A6,'Vehicle information'!$A$2:$F$72,5,FALSE)

Thanks again.
 
Upvote 0
Try this in the Sheet Module
Code:
Sub Worksheet_Change(ByVal Target As Range)
If Not (Target.Comment Is Nothing) Then Target.Comment.Delete
If Target.Count > 1 Then Exit Sub
 If Intersect(Target, Range("C6:C69")) Is Nothing Then Exit Sub 'change cell range to suit
        With Target.AddComment
        .Text "The Contact Person for This Vehicle is "
        End With
End Sub
 
Upvote 0
Based on post #7 maybe the comment text should be:
Code:
.Text "The Contact Person for This Vehicle is " & _
    WorksheetFunction.VLookup(target.Offset(0, -2), Sheets("Vehicle information").Range("$A$2:$F$72"), _
    5, False)
 
Upvote 0
Darn Joe, just got back....

Code:
Sub Worksheet_Change(ByVal Target As Range)
Dim x As String
If Not (Target.Comment Is Nothing) Then Target.Comment.Delete
If Target.Count > 1 Then Exit Sub
 If Intersect(Target, Range("C6:C69")) Is Nothing Then Exit Sub 'change cell range to suit
x = Application.WorksheetFunction.VLookup(Target.Offset(0, -2), Sheets("Vehicle information").Range("$A$2:$F$72"), 5, False)
    With Target.AddComment
        .Text "The Contact Person for This Vehicle is " & x
    End With
End Sub
your's is more efficient though...:pray:
 
Upvote 0

Forum statistics

Threads
1,215,506
Messages
6,125,193
Members
449,213
Latest member
Kirbito

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top