+ Reply to Thread
Results 1 to 6 of 6

Keep cell formatting while using VBA/Macros

  1. #1
    Registered User
    Join Date
    10-22-2018
    Location
    New Jersey
    MS-Off Ver
    2011
    Posts
    7

    Keep cell formatting while using VBA/Macros

    I am using the code below to generate 5 random names based on a target value. I have a list of names in column A and values for each in column B. The code pastes the names from column A across starting in column K. I want to color code the name by change the cells background color or text color and have it show up that way in the new cell after the Macro runs. Is this possible?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Keep cell formatting while using VBA/Macros

    Using this line of code as an example"
    Please Login or Register  to view this content.
    Change the line by making it part of a With statement
    Please Login or Register  to view this content.
    You can do that with each each line of similar code in the loop. The vb colors are limited to about eight, but the ColorIndex has 56 options.
    Last edited by JLGWhiz; 12-16-2018 at 01:30 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    10-22-2018
    Location
    New Jersey
    MS-Off Ver
    2011
    Posts
    7

    Re: Keep cell formatting while using VBA/Macros

    Quote Originally Posted by JLGWhiz View Post
    Using this line of code as an example"
    Please Login or Register  to view this content.
    Change the line by making it part of a With statement
    Please Login or Register  to view this content.
    You can do that with each each line of similar code in the loop. The vb colors are limited to about eight, but the ColorIndex has 56 options.
    Thanks for the reply but your options doesn't keep my formatting it changes it whatever I specify. I would it to keep the original cell formatting that I created prior to running the macro. Is there an edit for your code that does that?

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Keep cell formatting while using VBA/Macros

    If there are no formulas in the source cells, then a straight copy will maintain the formating.

    Please Login or Register  to view this content.
    If there are formulas in the source cells then you would need to copy and PasteSpecial xlPasteFormats
    example:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-22-2018
    Location
    New Jersey
    MS-Off Ver
    2011
    Posts
    7

    Re: Keep cell formatting while using VBA/Macros

    Perfect thank you!!!

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Keep cell formatting while using VBA/Macros

    Quote Originally Posted by cutty382 View Post
    Perfect thank you!!!
    You're welcome,
    Regards, JLG

+ 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] Name Formatting using Macros
    By rodeam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-17-2016, 09:39 AM
  2. Multi-step formatting macros with formatting and formulas
    By LG99 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2013, 10:57 PM
  3. [SOLVED] Macros imitating conditional formatting based on specific text within cell
    By schaasyd in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-15-2012, 06:30 PM
  4. Formatting data any macros for this
    By pravn_r in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2011, 12:10 PM
  5. Need help adjusting this Formatting Macros
    By copleyr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-15-2009, 10:27 AM
  6. Replies: 6
    Last Post: 05-19-2009, 02:53 AM
  7. If And Now formatting macros
    By ritz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-18-2007, 05:56 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