+ Reply to Thread
Results 1 to 8 of 8

Need VBA Code to "VLOOKUP" but keep source cell Formatting

  1. #1
    Registered User
    Join Date
    10-03-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    2

    Need VBA Code to "VLOOKUP" but keep source cell Formatting

    Hello all,

    I'm new to the forum and am needing some help. Attached is a VERY simple spreadsheet with Animals on Sheet1 and a table on Sheet2, also with the same animal names, but corresponding colors (each with different formatting). I know there is no way for the VLOOKUP to output the format of the source, so I'm looking for a VBA code to Find the matching Animal from Sheet1, on Sheet2, then output the Formatted Corresponding color back to Sheet 1, adjacent to that animal. For example,

    Lookup Sheet1, A3 ("Lion") on Sheet2, A2:B5, then output Sheet2, B5 (Red) to Sheet1,B3.

    I am using Excel 2003, but have the ability to use 2007 if needed. Thank you for your time.
    Attached Files Attached Files
    Last edited by flyyboy84; 11-01-2012 at 10:37 AM.

  2. #2
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    154

    Re: Need VBA Code to "VLOOKUP" but keep source cell Formatting

    Try this. This will copy the format that corresponds to the lookup value and paste the format to Sheet 1

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    818

    Re: Need VBA Code to "VLOOKUP" but keep source cell Formatting

    Quote Originally Posted by jkj115 View Post
    Try this. This will copy the format that corresponds to the lookup value and paste the format to Sheet 1

    Please Login or Register  to view this content.

    I got an error message when try your code:
    "Run-time error '1004'"
    Select method of Range class failed"

    Regards,
    tt3

  4. #4
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2010
    Posts
    154

    Re: Need VBA Code to "VLOOKUP" but keep source cell Formatting

    On what line of the code (go to VBA and hit f8 to click through the code step by step)? What are the names of your sheets

  5. #5
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    818

    Re: Need VBA Code to "VLOOKUP" but keep source cell Formatting

    Hi jkj115,

    The error is at below line and the names are Sheet1 and Sheet2

    Cells(x, 2).Select

    Regards,
    tt3

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Need VBA Code to "VLOOKUP" but keep source cell Formatting

    Try
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    08-14-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, MS 365 (Windows 10 Pro 64-bit)
    Posts
    818

    Re: Need VBA Code to "VLOOKUP" but keep source cell Formatting

    Quote Originally Posted by jindon View Post
    Try
    Please Login or Register  to view this content.
    Hi jindon,
    Your code is perfect and thank you for your help.

    Regards,
    tt3

  8. #8
    Registered User
    Join Date
    10-03-2012
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Need VBA Code to "VLOOKUP" but keep source cell Formatting

    This works PERFECTLY. Thank you so much jindon; you don't know how much time you just saved me!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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