VBA Macros for Conditional formatting and column hiding

Allan54

New Member
Joined
Oct 11, 2013
Messages
11
Hi All,

I am totally new to Macros. I need a Macro which should format a column based on the value of another column.

Consider I have 10 rows. I have to format column D, based on the value of Column E. If the value of Column E is > 1000, then the background color of Column D should be changed as green. The most important requirement is Column E should be invisible, Changing the font color of Column E as White does not seem ok cuz when we select the sheet entirely using Ctrl+A, the white values are very much visible. Can this be achieved using a macro?

Can anyone help please.
 
What about just hiding the entire row? Click on row E, right click, hide. Also, you can protect the workbook and make it where none of the other cells are protected except for column e.

If you don't want that I have two more options I can think of.
1) Intersect macro that when you click on any cell in column e, it makes you select the cell in column d instead (i don't know how to just 'unselect' a cell)
2)Intersect macro that protects the workbook when you click on any E cell, then unprotects it when you click on any other cell.
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Will this work? Hide the entire column instead?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    'loop through each cell in range
   For Each Row In Range("D:D")
       'exit loop if no more data to prevent infinite loop
       If Row.Value = "" Then
          Exit For
       End If
   
       'conditional formatting background color
       If Range(Row.Address).Offset(0, 1).Value > 1000 Then
          Range(Row.Address).Interior.Color = RGB(0, 153, 0) ' color cell green
       Else
          Range(Row.Address).Interior.ColorIndex = xlNone ' color cell with 'no fill'
       End If
   
      'set format to hide values in the cell in the next column
      'Range(Row.Address).Offset(0, 1).NumberFormat = ";;;"

   Next
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   'if column isn't hidden, hide it
   If Range("E:E").EntireColumn.Hidden = False Then
       Range("E:E").EntireColumn.Hidden = True
   End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,562
Messages
6,125,546
Members
449,237
Latest member
Chase S

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