Consulting

Results 1 to 3 of 3

Thread: Highlight the selected cell

  1. #1

    Highlight the selected cell

    Hi,

    I created a macro that can highlight the selected cell.

    However, my macro will clear the colour in all cell before it highlights the selected cell.

    Is it possible to amend it so that it will clear the colour in the previous selected cell only, rather than clearing colour in all cells?

    I want the macro that has this feature:

    Clear the colour in previous selected cell only, then highlight the current selected cell.


    [VBA]

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Set x = Selection

    Cells.Interior.ColorIndex = xlNone

    x.Interior.Color = 65535


    End Sub


    [/VBA]





    Thanks

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    [vba]
    Dim OldCell As String
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    Range(OldCell).Interior.ColorIndex = 0
    Target.Interior.Color = vbRed 'QBColor(10)
    OldCell = Target.Address
    End Sub[/vba]

  3. #3
    Quote Originally Posted by patel
    [vba]
    Dim OldCell As String
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    Range(OldCell).Interior.ColorIndex = 0
    Target.Interior.Color = vbRed 'QBColor(10)
    OldCell = Target.Address
    End Sub[/vba]
    Hi,

    Your macro does work.

    However, there is another problem that I can not resolve.

    If I used this macro, I am unable to do copy and paste.

    For example, I can not copy the data from cell A1 and then paste to cell B1.\

    I have added Application.CutCopyMode = true, but was not helpful.

    Could you please resolve that?

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •