Conditional format

trebor1956

Board Regular
Joined
Jul 2, 2015
Messages
100
Office Version
  1. 2013
Platform
  1. Windows
Is it possible to format text to white in column A if column B is unhidden but then format the text in column A to black when column B is hidden?
All help gratefully received
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Rigt click your sheet name, click on "code" and paste this

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sh As Worksheet: Set sh = ActiveSheet
'Last Row
 Dim lr As Long: lr = sh.Cells(sh.Rows.Count, "A").End(xlUp).Row

If Columns("B:B").Hidden = True Then
    Columns("A1:A"&lr).Font.ThemeColor = xlThemeColorDark1
    Else
    Columns([COLOR=#222222][FONT=Verdana]"A1:A"&lr[/FONT][/COLOR]).Font.ColorIndex = xlAutomatic
End If 'Column B visible
End Sub
When you hide column B and select a cell, A font is white. Unhide and click a cell, A font is black again.
 
Last edited:
Upvote 0
Sorry, code above is wrong. I applied the formula to columns("A:A") but this is not really good, it is better to apply it from A1 to last cell from A (so a range)

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sh As Worksheet: Set sh = ActiveSheet
'Last Row
 Dim lr As Long: lr = sh.Cells(sh.Rows.Count, "A").End(xlUp).Row
If Columns("B:B").Hidden = True Then
    Range("A1:A" & lr).Font.ThemeColor = xlThemeColorDark1
    Else
    Range("A1:A" & lr).Font.ColorIndex = xlAutomatic
End If 'Column B visible
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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