+ Reply to Thread
Results 1 to 16 of 16

Macro that copy selection of cells before changing font color

Hybrid View

  1. #1
    Registered User
    Join Date
    07-02-2018
    Location
    Drunen
    MS-Off Ver
    2013
    Posts
    60

    Macro that copy selection of cells before changing font color

    Hi all,

    I`m starting to learn about macro`s and VBA.

    Currently i`m using this macro to change the font color from the selection of cells :
    Sub Kleur_Copy()
    
        Dim rngCell As Range
        
        Application.ScreenUpdating = False
        
        For Each rngCell In Selection
        
            rngCell.Font.Color = RGB(0, 165, 0)
        Next rngCell
        
        Application.ScreenUpdating = True
        
    End Sub
    Now i want to add Copy.Selection to this so that it saves the selection onto the clipboard, however i can`t get it to copy without the changed font color. I know i can fix this with pasting values only, but is there a way to copy the values before changing font color?

    Kind regards,
    Last edited by MrMyagiii; 07-02-2018 at 11:53 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Macro that copy selection of cells before changing font color

    Put Selection.Copy as the first line of the procedure before you change the font color.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    07-02-2018
    Location
    Drunen
    MS-Off Ver
    2013
    Posts
    60

    Re: Macro that copy selection of cells before changing font color

    You mean like this?
    I tried this before but still gives the same result. The pasted text has changed font color. I dont understand why
    Sub Kleur_Copy()
    
    Copy.Selection
    
    Dim rngCell As Range
    
    Application.ScreenUpdating = False
    
    For Each rngCell In Selection
    
    rngCell.Font.Color = RGB(0, 165, 0)
    Next rngCell
    
    Application.ScreenUpdating = True
    
    End Sub
    Last edited by MrMyagiii; 07-02-2018 at 11:52 AM.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Macro that copy selection of cells before changing font color

    Quote Originally Posted by MrMyagiii View Post
    You mean like this?
    I tried this before but still gives the same result. The pasted text has changed font color. I dont understand why

    Sub Kleur_Copy()

    Copy.Selection

    Dim rngCell As Range

    Application.ScreenUpdating = False

    For Each rngCell In Selection

    rngCell.Font.Color = RGB(0, 165, 0)
    Next rngCell

    Application.ScreenUpdating = True

    End Sub
    The command is Selection.Copy (not Copy.Selection)

  5. #5
    Registered User
    Join Date
    07-02-2018
    Location
    Drunen
    MS-Off Ver
    2013
    Posts
    60

    Re: Macro that copy selection of cells before changing font color

    Yeah i know, my bad. But still doesn`t work with :
    Sub Kleur_Copy()
    
    Dim rngCell As Range
    
    Application.ScreenUpdating = False
    
    Selection.Copy
    
    For Each rngCell In Selection
    
    rngCell.Font.Color = RGB(0, 165, 0)
    Next rngCell
    
    Application.ScreenUpdating = True
    
    End Sub
    The pasted content still returns with the "new" font color
    Last edited by MrMyagiii; 07-02-2018 at 11:51 AM.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Macro that copy selection of cells before changing font color

    Quote Originally Posted by MrMyagiii View Post
    The pasted content still returns with the "new" font color

    What are you doing to paste the content? If you're using a macro to paste, have it remove the font color as well.

  7. #7
    Forum Contributor
    Join Date
    10-19-2012
    Location
    chennai
    MS-Off Ver
    Excel 2013
    Posts
    134

    Re: Macro that copy selection of cells before changing font color

    Hi,

    Try below one

    Sub Kleur_Copy()
    
    Dim rngCell As Range
    
    Application.ScreenUpdating = False
    
    Selection.Copy
    
    For Each rngCell In Selection
    
    rngCell.Font.Color = RGB(0, 165, 0)
    Next rngCell
    
    Application.ScreenUpdating = True
    
    End Sub
    RoyalRajan

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro that copy selection of cells before changing font color

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Macro that copy selection of cells before changing font color

    You can Paste Special without a macro
    On the menu: Edit\PasteSpecial\Values

  10. #10
    Registered User
    Join Date
    07-02-2018
    Location
    Drunen
    MS-Off Ver
    2013
    Posts
    60

    Re: Macro that copy selection of cells before changing font color

    Ok so i have to look for a solution in the "paste" direction. It is not possible to copy without changed font color?

  11. #11
    Forum Contributor
    Join Date
    10-19-2012
    Location
    chennai
    MS-Off Ver
    Excel 2013
    Posts
    134

    Re: Macro that copy selection of cells before changing font color

    Hi,


    Ii works pls check the attached sheet and below code. maybe you have selected default font color as green try after changing it into black.

    Sub Kleur_Copy()
    Dim rngCell As Range
    Application.ScreenUpdating = False
    ActiveCell.CurrentRegion.Select
    Selection.Copy
    For Each rngCell In Selection
    rngCell.Font.Color = RGB(0, 165, 0)
    Next rngCell
    Application.ScreenUpdating = True
    Range("a1").Select
    Selection.PasteSpecial (xlPasteValues)
    End Sub
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    10-19-2012
    Location
    chennai
    MS-Off Ver
    Excel 2013
    Posts
    134

    Re: Macro that copy selection of cells before changing font color

    Hi,

    try this one

    [code]

    Sub Kleur_Copy()
    Dim rngCell As Range
    Application.ScreenUpdating = False
    ActiveCell.CurrentRegion.Select
    Selection.Copy
    Workbooks.Add
    Windows("Book1").Activate
    Selection.PasteSpecial (xlPasteValues)
    ThisWorkbook.Activate
    For Each rngCell In Selection
    rngCell.Font.Color = RGB(0, 165, 0)
    Next rngCell
    Application.ScreenUpdating = True
    End Sub

    [\code]

  13. #13
    Registered User
    Join Date
    07-02-2018
    Location
    Drunen
    MS-Off Ver
    2013
    Posts
    60

    Re: Macro that copy selection of cells before changing font color

    Gives an error on :
    ActiveCell.Currentregion.select

    The worksheet is protected, however the cells that need to be copied and changed are available

+ 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] Macro changing font color to white instead of gray
    By bwmuhich in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-20-2015, 10:40 PM
  2. Changing font Color linked to Date Key through macro
    By JPSIMMON in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-19-2014, 04:38 PM
  3. Changing font color
    By ceb39usa in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-06-2014, 03:08 AM
  4. Replies: 2
    Last Post: 02-04-2013, 02:00 PM
  5. Replies: 0
    Last Post: 07-17-2007, 03:23 PM
  6. Changing Font Color
    By bagoxc in forum Excel General
    Replies: 2
    Last Post: 07-16-2006, 08:20 PM
  7. [SOLVED] selection.font.color returns wrong color; the first execution
    By AnExpertNovice in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-07-2006, 08:35 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