Curser Highlight

G

Guest

Does anyone know how to make the cell highlight, only when it it selected,
and keep moving with the curser as you move around the spreadsheet?
 
G

Guest

Paste this into the files Thisworkbook Module - Selected cell will be
highlighted
in all your sheets - even better this macro does not affect existing
Conditional formatting..



Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
Static OldCell As Range
If Application.CutCopyMode = 0 Then
If Not OldCell Is Nothing Then
OldCell.Interior.ColorIndex = xlColorIndexNone
OldCell.Borders.LineStyle = xlLineStyleNone
End If
Set OldCell = Target
OldCell.Interior.ColorIndex = 6
OldCell.Borders.LineStyle = xlContinuous
Else
If OldCell Is Nothing Then
Set OldCell = Target
Else
Set OldCell = Union(OldCell, Target)
End If
End If
End Sub
 
G

Guest

Jim May said:
Paste this into the files Thisworkbook Module - Selected cell will be
highlighted
in all your sheets - even better this macro does not affect existing
Conditional formatting..



Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
Static OldCell As Range
If Application.CutCopyMode = 0 Then
If Not OldCell Is Nothing Then
OldCell.Interior.ColorIndex = xlColorIndexNone
OldCell.Borders.LineStyle = xlLineStyleNone
End If
Set OldCell = Target
OldCell.Interior.ColorIndex = 6
OldCell.Borders.LineStyle = xlContinuous
Else
If OldCell Is Nothing Then
Set OldCell = Target
Else
Set OldCell = Union(OldCell, Target)
End If
End If
End Sub
 
G

Guest

Thanks Jim That is cool!

Jim May said:
Paste this into the files Thisworkbook Module - Selected cell will be
highlighted
in all your sheets - even better this macro does not affect existing
Conditional formatting..



Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
Static OldCell As Range
If Application.CutCopyMode = 0 Then
If Not OldCell Is Nothing Then
OldCell.Interior.ColorIndex = xlColorIndexNone
OldCell.Borders.LineStyle = xlLineStyleNone
End If
Set OldCell = Target
OldCell.Interior.ColorIndex = 6
OldCell.Borders.LineStyle = xlContinuous
Else
If OldCell Is Nothing Then
Set OldCell = Target
Else
Set OldCell = Union(OldCell, Target)
End If
End If
End Sub
 
M

Max

Nice sub there, Jim.

Is there a way for a user choice to toggle the feature on/off, when the wb
is opened?

Eg: when I'm working on the wb, I may want it to be toggled off so that undo
is not disabled (as per normal). But when I'm presenting/discussing the wb
with others, I wld like to have the cell highlight feature "on".

Thanks

---
 
G

Guest

Thanks Max;
My initial response goes to perhaps setting up a Flag (boolean) type for
On/Off, True/False... you know...
 
M

Max

Thanks Max;
My initial response goes to perhaps setting up a Flag (boolean) type for
On/Off, True/False... you know

I won't know how to do that <g>.
Any sample code how it could be worked into here?
 
G

Guest

Here's my entire code:
1) Paste these top two (2) macros into your ThisWorkbook Module.
2) Paste the next Block (one Declaration ststement & one Macro into a
Standard module)
3) Use the Forms Command Button and assign the TogglebFlag macro to it.

Hope that helps..
Jim

Private Sub Workbook_Open()
bFlag = True
ActiveCell.Interior.ColorIndex = xlColorIndexNone
ActiveCell.Borders.LineStyle = xlLineStyleNone
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target
As Range)
Static OldCell As Range
If bFlag = True Then
If Application.CutCopyMode = 0 Then
If Not OldCell Is Nothing Then
OldCell.Interior.ColorIndex = xlColorIndexNone
OldCell.Borders.LineStyle = xlLineStyleNone
End If
Set OldCell = Target
OldCell.Interior.ColorIndex = 6
OldCell.Borders.LineStyle = xlContinuous
Else
If OldCell Is Nothing Then
Set OldCell = Target
Else
Set OldCell = Union(OldCell, Target)
End If
End If
End If
End Sub

2:

Public bFlag As Boolean ' This should appear in the Declarations Section

Sub TogglebFlag()
Set OldCell = Nothing
ActiveCell.Interior.ColorIndex = xlColorIndexNone
ActiveCell.Borders.LineStyle = xlLineStyleNone
If bFlag = True Then
bFlag = False
Else: bFlag = True
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top