+ Reply to Thread
Results 1 to 16 of 16

Returning cell values in a comment based on values in another workbook

  1. #1
    Forum Contributor
    Join Date
    11-26-2008
    Location
    UK
    MS-Off Ver
    Using Excel 2019
    Posts
    317

    Returning cell values in a comment based on values in another workbook

    Hi,

    I have Workbook1 with cell values in B7:B500. These can be conditionally formatted. I'd like vba code to do the following:

    1. Check the cells in B7:B500 in Workbook1
    2. If the text in a cell is a certain colour (standard excel red)
    3. look up the value of the cell in Workbook2 (A2:A500)
    4. Once the value is matched then find the values on the same row but in columns F and G.
    5. Return these values in a comment in the cell containing the original value in Workbook1 (ie in B7:B500)



    Any takers? Help much appreciated.
    Last edited by Barking_Mad; 04-10-2014 at 03:34 AM.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Returning cell values in a comment based on values in another workbook

    What version of excel?

    In VBA the interior.colour property of a cell is the colour without any conditional formatting applied, so if the conditional formatting changes the colour of the cell, then this will not be picked up. I'm assuming that you are referring to conditional formatted colours in your question so in later versions you can use .displayformat but in 2003 and earlier you need to use this sort of thing:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    11-26-2008
    Location
    UK
    MS-Off Ver
    Using Excel 2019
    Posts
    317

    Re: Returning cell values in a comment based on values in another workbook

    Hi,

    It's 2010 version. Ill have a look at the code, but im guessing i wont get very far! lol

    Thanks

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Returning cell values in a comment based on values in another workbook

    Ok, so in 2010 you should be able to use
    .displayformat
    rather than the code I posted, unfortunately I'm not familiar with the .displayformat property, I'll see if someone else can help.

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Returning cell values in a comment based on values in another workbook

    Which sheets in each workbook? You basically just need to test if the DisplayFormat.Font.Color = vbRed (or whatever colour you are interested in).
    Remember what the dormouse said
    Feed your head

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Returning cell values in a comment based on values in another workbook

    Here's a rough example:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-26-2008
    Location
    UK
    MS-Off Ver
    Using Excel 2019
    Posts
    317

    Re: Returning cell values in a comment based on values in another workbook

    Hi Thanks Romperstomper - i actually need to to work as a private sub, so it runs on each worksheet (they'll all be generated from a template). Do i just use the location of the workbook (ie. C/Desktop/Workbook2.xlsx) in place of "Workbook2.xlsx" ?

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Returning cell values in a comment based on values in another workbook

    No - the workbook has to be open, so you refer to it only by name, not path.

  9. #9
    Forum Contributor
    Join Date
    11-26-2008
    Location
    UK
    MS-Off Ver
    Using Excel 2019
    Posts
    317

    Re: Returning cell values in a comment based on values in another workbook

    Quote Originally Posted by romperstomper View Post
    No - the workbook has to be open, so you refer to it only by name, not path.
    Ahh ok it cant be open due to various reasons i wont bore you with... so if i could instead put that data in another sheet (say "Names" in the same workbook that the comments are to be placed in - what would the code look like then?

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Returning cell values in a comment based on values in another workbook

    Assuming the code is in the same workbook, change this:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    11-26-2008
    Location
    UK
    MS-Off Ver
    Using Excel 2019
    Posts
    317

    Re: Returning cell values in a comment based on values in another workbook

    Quote Originally Posted by romperstomper View Post
    Assuming the code is in the same workbook, change this:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.

    Thanks so much, that works spot-on. Many thanks!
    Last edited by Barking_Mad; 04-09-2014 at 10:39 AM.

  12. #12
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Returning cell values in a comment based on values in another workbook

    Glad to help.

  13. #13
    Forum Contributor
    Join Date
    11-26-2008
    Location
    UK
    MS-Off Ver
    Using Excel 2019
    Posts
    317

    Re: Returning cell values in a comment based on values in another workbook

    Oh just noticed one thing - it runs as desired the first time - but when it runs again (on unchanged data) I get an error:

    Application-defined or object-defined error.

    on code in bold:

    Please Login or Register  to view this content.

  14. #14
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Returning cell values in a comment based on values in another workbook

    I did say it was rough.

    Please Login or Register  to view this content.
    Note: this will replace any existing comment text. Not sure if you want that or to add it.

  15. #15
    Forum Contributor
    Join Date
    11-26-2008
    Location
    UK
    MS-Off Ver
    Using Excel 2019
    Posts
    317

    Re: Returning cell values in a comment based on values in another workbook

    Quote Originally Posted by romperstomper View Post
    I did say it was rough.

    Please Login or Register  to view this content.
    Note: this will replace any existing comment text. Not sure if you want that or to add it.
    Thanks Your rough is better than my not at all! I can understand vb when i see it coded, but actually trying to get any of it to stick in my mind is like throwing jelly at a wall! Replacing comments will be fine

  16. #16
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Returning cell values in a comment based on values in another workbook

    We all started somewhere - perhaps this will be the beginning of your journey into VBA madness.

+ 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. Replies: 4
    Last Post: 05-29-2013, 04:18 AM
  2. Returning a value to a single cell based on multiple values elsewhere.
    By archieross in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-05-2012, 07:35 PM
  3. Replies: 0
    Last Post: 09-28-2012, 07:55 AM
  4. Replies: 0
    Last Post: 04-30-2012, 12:02 PM
  5. Replies: 2
    Last Post: 02-01-2012, 06:28 PM

Tags for this Thread

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