Excel

Automatic Highlighting Using Conditional Formatting

Ease of Use

Easy

Version tested with

97, 2003 

Submitted by:

Andrew

Description:

An easy way to implement Automatic Highlighting. 

Discussion:

Take advantage of the CELL function - if no range is specified in the formula, it refers to the active cell. ScreenUpdating updates the highlighted cells when a new selection is made. 

Code:

instructions for use

			

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) Application.ScreenUpdating = True End Sub

How to use:

  1. Open the Visual Basic Editor (push Alt + F11 simultaneously).
  2. Paste the above code in ThisWorkbook.
  3. To use with single sheets only, replace the top line with "Private Sub Worksheet_SelectionChange(ByVal Target As Range)" (without quote marks)
  4. Return to Excel and select your range.
  5. Go to Format, Conditional Formatting on the top menu.
  6. Select Formula Is and enter one or more of the formats shown below and in the attached file.
  7. Push the Format button and choose the Font, Borders, Pattern format or combination of your choice, then push OK.
 

Test the code:

  1. Formula Is
  2. Highlight Active Cell
  3. =CELL("address")=ADDRESS(ROW(),COLUMN())
  4. Highlight Active Row
  5. =CELL("row")=ROW()
  6. Highlight row and column
  7. =OR(AND(CELL("row")=ROW(),CELL("col")+1>COLUMN()),AND(CELL("col")=COLUMN(),CELL("row")+1>ROW()))
  8. Hybrid - Active cell with row and column
  9. =CELL("address")=ADDRESS(ROW(),COLUMN())
  10. =OR(AND(CELL("row")=ROW(),CELL("col")+1>COLUMN()),AND(CELL("col")=COLUMN(),CELL("row")+1>ROW()))
 

Sample File:

Automatic_Highlighting.zip 10.07KB 

Approved by mdmackillop


This entry has been viewed 337 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express