+ Reply to Thread
Results 1 to 7 of 7

Set Text color to Cell color

Hybrid View

barnarp Set Text color to Cell color 05-02-2013, 04:37 AM
AndyLitch Re: Set Text color to Cell... 05-02-2013, 04:54 AM
barnarp Re: Set Text color to Cell... 05-02-2013, 06:24 AM
barnarp Re: Set Text color to Cell... 05-02-2013, 06:20 AM
AndyLitch Re: Set Text color to Cell... 05-06-2013, 05:05 AM
barnarp Re: Set Text color to Cell... 05-06-2013, 06:29 AM
AndyLitch Re: Set Text color to Cell... 05-06-2013, 07:17 AM
  1. #1
    Registered User
    Join Date
    05-02-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    4

    Set Text color to Cell color

    Hi all,

    New to the forum and to excel macros.

    I am trying to remove the numbers from conditional formatted cells and just keep the cell color.

    I am not sure it can be done, but I have tried this macro which should change the text color of the cell to the same cell color of the cell in order to "hide" the text.

    It doesn't work 100%, can someone please have a look at this and advise?

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim LastRow, LastCol, BackgroundColor, mycell
    LastRow = Application.Cells.SpecialCells(xlCellTypeLastCell).Row
    LastCol = Application.Cells.SpecialCells(xlCellTypeLastCell).Column
    mycell Range
    For i = 1 To LastRow
    For j = 1 To LastCol
    If IsNumeric(Cells(i, j)) Then
    BackgroundColor = Cells(i, j).Interior.ColorIndex
    Cells(i, j).Font.ColorIndex = BackgroundColor
    End If
    Next j
    Next i
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Set Text color to Cell color

    The Cell colour set by conditional format is not the same as the cell.interior.color property.

    Cells(i, j).FormatConditions(1).Interior.Color
    would give you the colour of format condition 1 but NOT whether the condition is TRue or not

    but you can programmatically check whether the format condition is true
    Elegant Simplicity............. Not Always

  3. #3
    Registered User
    Join Date
    05-02-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Set Text color to Cell color

    This code works on non formatted cells, but changed the text to WHITE and not the color of the cell?

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim LastRow, LastCol, BackgroundColor, mycell
    LastRow = Application.Cells.SpecialCells(xlCellTypeLastCell).Row
    LastCol = Application.Cells.SpecialCells(xlCellTypeLastCell).Column
    For i = 1 To LastRow
    For j = 1 To LastCol
    If IsNumeric(Cells(i, j)) Then
    BackgroundColor = Cells(i, j).Interior.Color
    Cells(i, j).Font.Color = BackgroundColor
    End If
    Next j
    Next i
    End Sub

  4. #4
    Registered User
    Join Date
    05-02-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Set Text color to Cell color

    Thanks, keep getting subscript out of range...

  5. #5
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Set Text color to Cell color

    That code looks fine to me........

    an alternative method might be to change the numberformat to make it invisible

    Cells(i, j).NumberFormat = ";;;"

  6. #6
    Registered User
    Join Date
    05-02-2013
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Set Text color to Cell color

    Quote Originally Posted by AndyLitch View Post
    That code looks fine to me........

    an alternative method might be to change the numberformat to make it invisible

    Cells(i, j).NumberFormat = ";;;"
    This works great, thanks.

  7. #7
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Set Text color to Cell color

    Anytime bro..

+ 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