+ Reply to Thread
Results 1 to 8 of 8

Add Comment Based on adjacent cell value (vlookup?)

Hybrid View

  1. #1
    Registered User
    Join Date
    05-11-2015
    Location
    St Louis
    MS-Off Ver
    2007 (Work) & 2013 (Personal)
    Posts
    4

    Add Comment Based on adjacent cell value (vlookup?)

    Hello all,

    So I have been browsing all morning and have yet to find anything that I've been able to modify for my use. So here goes and I appreciate all help!


    I have a sheet ""project" that has customer #'s in Column A and then several columns of various data that is pulled in from other hidden sheets.

    One of those other sheets is a rebate detail - it has two columns, A & B. A is customer # and B is concatenated info of all the types of rebates (it has been pasted as a text/value so no formula).

    I would like to create a comment box on my original sheet (project) that would appear in Column AB that returns the results of a vlookup on the customer number from column A. I want to do a comment box, because that cell already has a formula result in it and I don't want to modify that cell, just add the comment as supplemental info.


    I've found a few items that were close - but nothing that I've been able to manipulate. I'm new to VBA and have done simple formatting and search macro's but nothing like this, I thought it would be easy haha.
    Any help is appreciated - I hope that was clear?

    THANK YOU!

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Add Comment Based on adjacent cell value (vlookup?)

    Well the sheet would help, but the VBA code to add a comment is:

    Range("J9").AddComment WorksheetFunction.VLookup(Range("I9").Value, Range("A2:B4"), 2, False)
    In the example, the comment goes into J9, the value to search is I9, looking for a match in A2:B4, returns the value in the second column (of A2:B4), and only returns an exact match... I presume you can probably modify as required, if not let me know and I can give more detail.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    05-11-2015
    Location
    St Louis
    MS-Off Ver
    2007 (Work) & 2013 (Personal)
    Posts
    4

    Re: Add Comment Based on adjacent cell value (vlookup?)

    Thank you for response -

    I've stripped out most of the info and uploaded the basic sheet (minus formatting). I appreciate your help and any additional detail you can offer would be awesome!

    Trying to add the comment box to column AE based on the Account # (Column A) with info from the "Rebate Info" sheet.

    I'm an newbie when it comes to VBA - I know how to read it and understand what's going on - but writing it is completely foreign to me (but I'm getting better - I hope?) I understand everything you posted but I'm not sure how to expand/apply it to the entire columns of the workbook.
    Attached Files Attached Files

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Add Comment Based on adjacent cell value (vlookup?)

    This code should help...

    Sub addcomments()
    
    Dim lastrow As Long
    Dim i As Long
    Dim ws As Worksheet
    Dim ws_rebate As Worksheet
    
    Set ws = Worksheets("D Data") 'the sheet getting the comments, change as needed
    Set ws_rebate = Worksheets("Rebate Info") 'the source of the comment content.
    lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row 'finds last row of data in Column A, change the "A" if needed
    On Error Resume Next 'if vlookup fails just go to next line
    For i = 3 To lastrow 'starts at 3 as per example book, if data starts on a different row, adjust
        ws.Range("AE" & i).ClearComments 'removes old comment in cell
        'in the line below AE gets the comment, by looking up column A value in the rebate sheet in the range A2 to B9.  Change A2:B9 as needed.
        ws.Range("AE" & i).AddComment WorksheetFunction.VLookup(Sheets(1).Range("A" & i).Value, Sheets(2).Range("A2:B9"), 2, False)
    Next i
    On Error GoTo 0 'resume normal error conditions
    
    End Sub

  5. #5
    Registered User
    Join Date
    05-11-2015
    Location
    St Louis
    MS-Off Ver
    2007 (Work) & 2013 (Personal)
    Posts
    4

    Re: Add Comment Based on adjacent cell value (vlookup?)

    Dude!
    So, that works perfectly on the sample sheet I uploaded - thank you! That is exactly what I was looking for.

    I'm having some glitches/difficulty implementing it in the full file with all data - I'm going to try and work through those for a bit. Thank you for the comments in the code as well huge learning tool - that was perfect.

    Thanks again. I may reach back out if I'm unable to resolve the minor glitches in the full file. But otherwise - perfect.

    Thanks again.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Add Comment Based on adjacent cell value (vlookup?)

    Astinn, no probs at all, glad I could help and that it seems to work as you want. Yes if you have problems incorporating it, let me know.

  7. #7
    Registered User
    Join Date
    05-11-2015
    Location
    St Louis
    MS-Off Ver
    2007 (Work) & 2013 (Personal)
    Posts
    4

    Re: Add Comment Based on adjacent cell value (vlookup?)

    Arkadi - worked out my bugs. Just needed to change some of the Sheet references in the vlookup. My original file was not sheets 1 & 2 - it was more like sheet5 & sheet14. But all good now! Thank you for the help!

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Add Comment Based on adjacent cell value (vlookup?)

    Sorry! Had an issue due to a typo and changed them, then forgot to fix it... Sheets(1) should just be WS and sheets(2) was WS_rebate

+ 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. How to prompt comment box based on cell value= 1-3
    By nadagoat in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-09-2014, 03:57 PM
  2. Putting the results of a vlookup into a cell's comment
    By trishcollins in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2014, 04:38 PM
  3. Insert comment based on Cell Value
    By Will03 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-07-2013, 09:10 AM
  4. [SOLVED] Vlookup while pulling a cell color and comment
    By wendy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-19-2006, 01:15 PM
  5. [SOLVED] How can I get a cell's comment moved into an adjacent cell as a st
    By Mark from Princeton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2005, 02:05 PM

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