+ Reply to Thread
Results 1 to 6 of 6

VBA Code to create hover-over message:

  1. #1
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    VBA Code to create hover-over message:

    Hello All,
    I'm trying to figure out how I can build some VBA code that will automatically add hover-over to specific text in a specific column. For example, for every cell in column C, if the number "20" exists, add a hover-message (pop-up box? Not sure what it's called) that would say "California", every time number "30" exists add a hover-message that says "New York", etc.

    If someone can just point me to the framework for this I can probably figure out how to iron out the details.

    Thanks a ton!
    Last edited by Chad Bateman; 03-01-2015 at 07:35 PM.

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: VBA Code to create hover-over message:

    It's called a cell comment. If you google it you will get lots of websites with sample code, some videos etc. Go into the help search box in the visual basic editor and search cell comment and you'll get a lot of help there also.

    Here's a sample:

    Excel Developer Reference
    Comment Object
    Represents a cell comment.
    Remarks


    The Comment object is a member of the Comments collection.


    Example


    Use the Comment property to return a Comment object. The following example changes the text in the comment in cell E5.

    Visual Basic for Applications
    Worksheets(1).Range("E5").Comment.Text "reviewed on " & Date

    Use Comments(index), where index is the comment number, to return a single comment from the Comments collection. The following example hides comment two on worksheet one.

    Visual Basic for Applications
    Worksheets(1).Comments(2).Visible = False

    Use the AddComment method to add a comment to a range. The following example adds a comment to cell E5 on worksheet one.

    Visual Basic for Applications
    With Worksheets(1).Range("e5").AddComment
    .Visible = False
    .Text "reviewed on " & Date
    End With
    Good Luck!!!
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA Code to create hover-over message:

    Hi Chad,

    Actually it's called 'Screen Tip Text' (analogous to 'Control Tip Text' on UserForm controls). It is not a COMMENT. It is created by putting a 'Dummy Hyperlink' in each cell that has an appropriate value.

    You have to modify Sub GetScreenTipTextValue() [in blue below] to assign the correct text values to numbers.

    See the attached sample working file and the code that follows:

    Sheet Code:
    Please Login or Register  to view this content.

    Ordinary Module Code such as 'Module1':
    Please Login or Register  to view this content.
    Lewis

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: VBA Code to create hover-over message:

    So you can't add a comment to a cell based on a value in that cell and change that comment based on the worksheet change event?
    I have some comments that I've added through code and although they weren't based on values in the cells they didn't require very much code. They also come up when I hover over the cell they are in, hence the reason for my apparent stupidity by saying it was a COMMENT.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA Code to create hover-over message:

    Hi skywriter,

    So you can't add a comment to a cell based on a value in that cell and change that comment based on the worksheet change event?.
    Yes you can. Adding comments is a perfectly valid way to solve the problem. Hyperlinks seemed like a superior method to me for this application because:
    a. Comments have to be formatted to remove the extra whitespace.
    b. It is relatively easy to accidentally change a comment, make a comment visible all the time, or to delete a comment.

    Just my opinion.

    Lewis

  6. #6
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: VBA Code to create hover-over message:

    Hi Lewis,
    I'm resurrecting this thread if I may. What you've managed to do is exactly what I'm looking to do with my worksheet. I've analyzed your code and played with your sample workbook in an effort to figure out how to apply it to my application. I hope you don't mind me reaching out for some help.

    On my worksheet (ws_gui)
    Range("I13:I19") all contain the values "+"
    Range("J13:J19") all contain the values "~"
    Range("K13:K19") all contain the values "-"

    What I am trying to accomplish to to display the appropriate "texttip" when the user hovers over one of those cells. The user will be able to then click on a cell to execute some code. The 'screentiptext' value will be different depending on the row of the cell. With the code below that I borrowed from you and attempted to adapt (really all I did was change the constant range reference and it's variable name, I'm not getting anything happening so clearly I am missing something in my adaptation. Note that the worksheet is protected but these ranges are not locked.

    Here is my code from a module within my workbook.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by Jenn68; 12-20-2021 at 03:36 PM. Reason: Cleaned up readability

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mouse Hover over a shape or picture and will display a text message
    By BI Guy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-18-2014, 10:17 AM
  2. Code to change shape colour with mouse hover
    By lorettag1966 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-04-2014, 10:16 PM
  3. [SOLVED] Excel VB code. Message pops up while code running asking question. Code must not wait.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2014, 06:10 AM
  4. Create Pop up message
    By chatnet in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-11-2012, 05:18 AM
  5. [SOLVED] Create Pop Up Message
    By mjg060468 in forum Excel General
    Replies: 1
    Last Post: 04-20-2012, 08:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1