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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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