+ Reply to Thread
Results 1 to 15 of 15

VBA to Vlookup cell text and return value as Cell Comment

  1. #1
    Registered User
    Join Date
    10-01-2017
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    7

    VBA to Vlookup cell text and return value as Cell Comment

    Hello,

    I am a beginner to VBA and I am trying to vlookup the cell values of column A in Datasheet from columns A:B in Mapping sheet. I want to return the value from Mapping sheet column B to Data sheet Column A in the form of a cell comment.

    The other caveat is that Column A in data sheet contains duplicate values and I only want to return a comment in the first instance of the cell value. I’ve attached my working file. Your help would be greatly appreciated.

    Thank you,
    Alex

    Edit: Attached corrected file
    Attached Files Attached Files
    Last edited by alexcapone; 10-29-2017 at 09:20 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: VBA to Vlookup cell text and return value as Cell Comment

    There is no matching data

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: VBA to Vlookup cell text and return value as Cell Comment

    But if you did have matching cells the code would look like this.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-01-2017
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to Vlookup cell text and return value as Cell Comment

    Yes, that worked like a charm! Sorry the reason it was not returning matches is because the cell text was slightly different and in a different column. But the code works perfectly for returning the comment. The only thing was that it returns the comment for every cell. Do you know how to return the comment only for the first instance of that cell text? For example, if the cell text was Deepwater Asgard it would only return it for the first instance but every other time Deepwater Asgard is in the column then no comment is entered.

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: VBA to Vlookup cell text and return value as Cell Comment

    Sure thing, we'll just use collections and find....
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-01-2017
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to Vlookup cell text and return value as Cell Comment

    Thanks but is there a reason why you took the vlookup function out of the second set of code? I don't think it will work without a vlookup function and I am having trouble merging your first and second sets of code. I think in my OP i stated the wrong column which is why I suspect you removed the vlookup function. I was trying to lookup column B in data sheet and return column B in the array on the Mapping sheet. I don’t see how that could be done without a vlookup. I am trying to re-attach the spreadsheet to show you the desired result but its not letting me attach anymore.

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: VBA to Vlookup cell text and return value as Cell Comment

    I am not sure why you would think Vlookup() would be better than the find code? Don't use the 1st code, just use the 2nd code.

  8. #8
    Registered User
    Join Date
    10-01-2017
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to Vlookup cell text and return value as Cell Comment

    I'm not seeing anything when I run the second set of code. I tried copying the contents of column B into Column A on the data sheet and then tried again to run the macro this is the result:


    Second Set of Code.PNG

    However, this is the desired result (I manually created this):

    Desired Result.PNG

  9. #9
    Registered User
    Join Date
    10-01-2017
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to Vlookup cell text and return value as Cell Comment

    I should also point out that the difference between the rig names between the mapping sheet and data was an extra underscore at the end of each name which is why the original vlookup didn't return any results. I removed that underscore in the mapping sheet when I run the macro in the above screenshots.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA to Vlookup cell text and return value as Cell Comment

    This works for me.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  11. #11
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: VBA to Vlookup cell text and return value as Cell Comment

    I don't know why you can't upload a new wb, possibly it is too large of a file or maybe you are trying to upload a file with the same name?

  12. #12
    Registered User
    Join Date
    10-01-2017
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to Vlookup cell text and return value as Cell Comment

    Quote Originally Posted by davesexcel View Post
    I don't know why you can't upload a new wb, possibly it is too large of a file or maybe you are trying to upload a file with the same name?
    Okay, I figured out how to attach the corrected file in the original post. Sorry for the confusion.

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA to Vlookup cell text and return value as Cell Comment

    Did you try the code in Post#10 ?

  14. #14
    Registered User
    Join Date
    10-01-2017
    Location
    Texas
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to Vlookup cell text and return value as Cell Comment

    Quote Originally Posted by bakerman2 View Post
    Did you try the code in Post#10 ?
    Sorry, I scrolled to the end and missed your post. Yes! This works. Thank you, sir!

  15. #15
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA to Vlookup cell text and return value as Cell Comment

    You're welcome and thanks for rep+.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. [SOLVED] Function to return comment from a cell, or null string if no comment
    By Monkihunta in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-22-2017, 01:01 PM
  2. Replies: 5
    Last Post: 03-31-2016, 08:52 AM
  3. [SOLVED] Vba to make new text from cell change post at beginning of cell comment not the end
    By M38512P in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-04-2015, 11:23 AM
  4. [SOLVED] Return Value from cell comment
    By rodgersmg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-20-2014, 04:37 AM
  5. VLOOKUP return value based on text in cell
    By Detrie in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-04-2014, 07:17 PM
  6. Cell's text / comment (no comment )
    By Marianus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-22-2013, 06:05 AM
  7. [SOLVED] How to set Vlookup from a string of text in a cell and return the same manner
    By cathchin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-14-2012, 04:14 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