Highlight cells

lighting77

New Member
Joined
Apr 19, 2012
Messages
13
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Hi.
I need to highlight cells from active cell, vertically, horizontally, diagonally and anti diagonally in an excel sheet. These highlights move automatically with an active cell.
Could some one help. Thanks
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
This gets sluggish. The conditional formatting is fast, but that won't change the formatting until you activate a cell in some way. So I made a worksheet macro that performs a meaningless change on the selected cell - but it slows down performance.

MrExcelPlayground22.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXY
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Sheet13
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:Y25Expression=ROW(A1)-COLUMN(A1)=CELL("row")-CELL("col")textNO
A1:Y25Expression=ROW(A1)+COLUMN(A1)=CELL("Row")+CELL("Col")textNO
A1:Y25Expression=OR(ROW(A1)=CELL("row"),COLUMN(A1)=CELL("col"))textNO

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim KeyCells As Range

    Set KeyCells = Range("A1:Y25")

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
           Is Nothing Then

Target.Value = Target.Value

End If
End Sub
 
Upvote 0
I just saw this same problem this morning in linked-in of all places. They had a better approach on the VBA code:

Application.Calculate

instead of target.value=target.value
 
Upvote 0
Hi bro, I have no idea about vba codes but I’ll have a crack at it.
 
Upvote 0
In that case, after doing the conditional formatting, right-click on the sheet tab on the bottom, and 'view code'.

paste this bit in on the right:

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.Calculate
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,334
Members
452,636
Latest member
laura12345

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