I'm so close yet so far: VBA Toggle to hide/show all non black text in range

Status
Not open for further replies.

Melimob

Active Member
Joined
Oct 16, 2011
Messages
396
Office Version
  1. 365
Hi

This is the code I have:

Code:
Private Sub HideFont()
    Dim cell As Variant
    Dim rng As Range
    Set rng = Range("Table1[Country]")
    For Each cell In rng
       If cell.Font.Color <> 1 Then
       cell.Font.Color = cell.Interior.Color
       End If
    Next cell
End Sub

What I need it to do is:
if the font is black, do nothing
otherwise change to interior color
This piece is not working as it's just changing all to match interior so I think my IF statement is off?

then I have another sub which I'm hoping to change just the ones to interior to a blue.
I.e. ignore any font in black and show rest as blue
Once I work out the above if, I guess I can adapt the below as similar?

Code:
Sub UnhideFont()
    Dim cell As Variant
    Dim rng As Range
    Set rng = Range("Table1[Country]")
    For Each cell In rng
        cell.Font.Color = 25
    Next cell
End Sub

then I've wrapped this in a toggle button:

Code:
Private Sub ToggleButton2_Click()
If ToggleButton2.Value = True Then
 'This area contains the things you want to happen
'when the toggle button is not depressed
UnhideFont
Else
'This area contains the things you want to happen
'when the toggle button is depressed
 HideFont
  End If


End Sub

this is driving me crazy so really appreciate any advice please!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Please don't post the same question again. This one is now closed.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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