question

LaiKanLeon-4557 avatar image
0 Votes"
LaiKanLeon-4557 asked LaiKanLeon-4557 answered

Application Event - Target.Cells.Count > 0 does not work correctly

Hello

I have developed an Excel add-in which uses Application Event.


The foll code works quite well (but not perfectly)

Private Sub MyEventVar_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

MyEventVar.EnableEvents = True


If Target.Cells.Count > 0 Then '// PROBLEM IS HERE

With Target

'// Colouring the active cell yellow
.Worksheet.Cells.FormatConditions.Delete
.FormatConditions.Add xlExpression, , "TRUE"
.FormatConditions(1).Interior.Color = vbYellow


End With

End If

End Sub




What I want to do is this:
I want the active cell be be (temporarily) coloured yellow (because the inbuilt Excel cursor is not very visible, and there are many colours in my worksheet)

When ever you click a cell, its colour changes to yellow.
When you click another cell, the old cell becomes white again, and the new cell becomes yellow.
In brief, what I want is to highlight the current cell yellow.



Problem with my code

If I select more than 1 cell, the code works correctly. Even with 2 cells, or 3 cells etc

But if I select a SINGLE CELL (with my mouse), the cell does not turn yellow - and this is precisely what I want to achieve.

Can anybody help?

Thanks
Leon Lai




office-vba-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LaiKanLeon-4557 avatar image
0 Votes"
LaiKanLeon-4557 answered

Hi,

Never mind.

I got another method which works.

thanks
Leon

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.