VBA Need cell color in font color

sksanjeev786

Well-known Member
Joined
Aug 5, 2020
Messages
883
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Team,

I need the cell color on the data........

Book1
ABCDEFG
2Unaided Brand Awareness 8%9%0%9%7%-2%
3Aided Brand Awareness 94%95%1%91%97%6%
4Message Association18%19%1%17%22%5%
5Consideration Intent 45%57%12%41%69%28%
6Aided Brand Awareness 85%88%3%86%88%2%
7Total Ad Recall47%56%9%42%71%29%
8Digital Ad Recall 21%23%2%22%49%27%
Sheet1
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I'm guessing at what you want, as your request was a little vaguely worded. But by your title, I think you want to hide the values in cells by making the font the same color as the interior. If that is the case, this should work:

VBA Code:
Sub SomethinForSanjeev()

Dim rngCell As Range

For Each rngCell In Selection

  With rngCell

    .Font.Color = .Interior.Color

  End With

Next rngCell

End Sub
 
Upvote 0
I'm guessing at what you want, as your request was a little vaguely worded. But by your title, I think you want to hide the values in cells by making the font the same color as the interior. If that is the case, this should work:

VBA Code:
Sub SomethinForSanjeev()

Dim rngCell As Range

For Each rngCell In Selection

  With rngCell

    .Font.Color = .Interior.Color

  End With

Next rngCell

End Sub
Hi Wookie,

Thank you so much for your time on this

I need to change the font color based on the cell color we have and once font color changes (Green, Orange and Red Font data) then Cell background white is fine for me

Let me know if you need more update on this:)
Regards
Sanjeev
 
Upvote 0
In that case, this version worked for me (you will likely need to tweak depending on the actual color values of your cells).


VBA Code:
Sub SomethinForSanjeevPt2_ElectronicBoogaloo()

Dim rngCell As Range

For Each rngCell In Selection

  With rngCell

    Select Case rngCell.Interior.Color

      'You'll need to figure out how best to identify the cell colors
      Case Is = vbRed, vbGreen, rgbOrange
      
        .Font.Color = .Interior.Color
        .Interior.Pattern = xlNone

    End Select

  End With

Next rngCell

End Sub
 
Upvote 1
In that case, this version worked for me (you will likely need to tweak depending on the actual color values of your cells).


VBA Code:
Sub SomethinForSanjeevPt2_ElectronicBoogaloo()

Dim rngCell As Range

For Each rngCell In Selection

  With rngCell

    Select Case rngCell.Interior.Color

      'You'll need to figure out how best to identify the cell colors
      Case Is = vbRed, vbGreen, rgbOrange
     
        .Font.Color = .Interior.Color
        .Interior.Pattern = xlNone

    End Select

  End With

Next rngCell

End Sub
Hi Wookie,

Thank you so much for your help on this:). This works perfectly for me.
But i have a few scenarios mentioned in the below points

1. Can I get the grey cell color as empty as how we have it in B1 to B7 font color?
2. For orange can I get the color as blue color (RGB=0,122,192)

Thanks in advance :)

Below codes i have added RGB for now

Sub SomethinForSanjeevPt2_ElectronicBoogaloo()

Dim rngCell As Range

For Each rngCell In Selection

With rngCell

Select Case rngCell.Interior.Color

'You'll need to figure out how best to identify the cell colors
Case Is = RGB(204, 51, 51), RGB(150, 193, 29), RGB(255, 150, 0)

.Font.Color = .Interior.Color
.Interior.Pattern = xlNone

End Select

End With

Next rngCell

End Sub


Regards
Sanjeev
 
Upvote 0
Try this version:

VBA Code:
Sub SomethinForSanjeev_3D()
'Crafted by Wookiee at MrExcel.com


Dim rngCell As Range

For Each rngCell In Selection

  With rngCell

    Select Case rngCell.Interior.Color

      Case Is = RGB(204, 51, 51), RGB(150, 193, 29), RGB(191, 191, 191)
      
        .Font.Color = .Interior.Color
        .Interior.Pattern = xlNone

      Case RGB(255, 150, 0)
      
        .Font.Color = RGB(0, 122, 192)
        .Interior.Pattern = xlNone

    End Select

  End With

Next rngCell

End Sub
 
Upvote 1
Solution
Try this version:

VBA Code:
Sub SomethinForSanjeev_3D()
'Crafted by Wookiee at MrExcel.com


Dim rngCell As Range

For Each rngCell In Selection

  With rngCell

    Select Case rngCell.Interior.Color

      Case Is = RGB(204, 51, 51), RGB(150, 193, 29), RGB(191, 191, 191)
     
        .Font.Color = .Interior.Color
        .Interior.Pattern = xlNone

      Case RGB(255, 150, 0)
     
        .Font.Color = RGB(0, 122, 192)
        .Interior.Pattern = xlNone

    End Select

  End With

Next rngCell

End Sub
Wow!!!!!

Thank you so much for your hard work on this..:):)

Super Happy!!!!!!
 
Upvote 0

Forum statistics

Threads
1,215,111
Messages
6,123,152
Members
449,098
Latest member
Doanvanhieu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top