+ Reply to Thread
Results 1 to 3 of 3

FormatConditions appears to kill copypaste

  1. #1

    FormatConditions appears to kill copypaste

    I copied the code below from another thread here to highlight the
    current row and column. It works great but kills the ability to copy a
    cell or range. The "marching ants" disappear as soon as I change
    cells. Any ideas of how to overcome this?


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim iColor As Integer
    '// Note: Don't use IF you have Conditional
    '// formating that you want to keep!

    '// On error resume in case
    '// user selects a range of cells
    On Error Resume Next
    iColor = Target.Interior.ColorIndex
    'Leave On Error ON for Row offset errors

    If iColor < 0 Then
    iColor = 36
    Else
    iColor = iColor + 1
    End If

    '// Need this test incase Font color is the same
    If iColor = Target.Font.ColorIndex Then iColor = iColor + 1

    Cells.FormatConditions.Delete

    '// Horizontal color banding
    With Range("A" & Target.Row, Target.Address) 'Rows(Target.Row)
    .FormatConditions.Add Type:=2, Formula1:="TRUE"
    .FormatConditions(1).Interior.ColorIndex = iColor
    End With

    '// Vertical color banding
    With Range(Target.Offset(1 - Target.Row, 0).Address & ":" &
    Target.Offset(-1, 0).Address) 'Rows(Target.Row)
    .FormatConditions.Add Type:=2, Formula1:="TRUE"
    .FormatConditions(1).Interior.ColorIndex = iColor
    End With

    End Sub


  2. #2
    George Nicholson
    Guest

    Re: FormatConditions appears to kill copypaste

    Untested, but maybe something like right after "On Error Resume Next" :
    If Application.CutCopyMode <> False Then Exit Sub

    CutCopyMode is the current status of the "marching ants". If on (either
    xlCut or xlCopy) then your code is skipped. That should allow you to Paste.

    HTH,
    --
    George Nicholson

    Remove 'Junk' from return address.

    <[email protected]> wrote in message
    news:[email protected]...
    >I copied the code below from another thread here to highlight the
    > current row and column. It works great but kills the ability to copy a
    > cell or range. The "marching ants" disappear as soon as I change
    > cells. Any ideas of how to overcome this?
    >
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > Dim iColor As Integer
    > '// Note: Don't use IF you have Conditional
    > '// formating that you want to keep!
    >
    > '// On error resume in case
    > '// user selects a range of cells
    > On Error Resume Next
    > iColor = Target.Interior.ColorIndex
    > 'Leave On Error ON for Row offset errors
    >
    > If iColor < 0 Then
    > iColor = 36
    > Else
    > iColor = iColor + 1
    > End If
    >
    > '// Need this test incase Font color is the same
    > If iColor = Target.Font.ColorIndex Then iColor = iColor + 1
    >
    > Cells.FormatConditions.Delete
    >
    > '// Horizontal color banding
    > With Range("A" & Target.Row, Target.Address) 'Rows(Target.Row)
    > .FormatConditions.Add Type:=2, Formula1:="TRUE"
    > .FormatConditions(1).Interior.ColorIndex = iColor
    > End With
    >
    > '// Vertical color banding
    > With Range(Target.Offset(1 - Target.Row, 0).Address & ":" &
    > Target.Offset(-1, 0).Address) 'Rows(Target.Row)
    > .FormatConditions.Add Type:=2, Formula1:="TRUE"
    > .FormatConditions(1).Interior.ColorIndex = iColor
    > End With
    >
    > End Sub
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: FormatConditions appears to kill copypaste

    Don't use this code. Most code like this will clear the clipboard when you
    have copied a range.

    --
    Regards,
    Tom Ogilvy

    <[email protected]> wrote in message
    news:[email protected]...
    > I copied the code below from another thread here to highlight the
    > current row and column. It works great but kills the ability to copy a
    > cell or range. The "marching ants" disappear as soon as I change
    > cells. Any ideas of how to overcome this?
    >
    >
    > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    > Dim iColor As Integer
    > '// Note: Don't use IF you have Conditional
    > '// formating that you want to keep!
    >
    > '// On error resume in case
    > '// user selects a range of cells
    > On Error Resume Next
    > iColor = Target.Interior.ColorIndex
    > 'Leave On Error ON for Row offset errors
    >
    > If iColor < 0 Then
    > iColor = 36
    > Else
    > iColor = iColor + 1
    > End If
    >
    > '// Need this test incase Font color is the same
    > If iColor = Target.Font.ColorIndex Then iColor = iColor + 1
    >
    > Cells.FormatConditions.Delete
    >
    > '// Horizontal color banding
    > With Range("A" & Target.Row, Target.Address) 'Rows(Target.Row)
    > .FormatConditions.Add Type:=2, Formula1:="TRUE"
    > .FormatConditions(1).Interior.ColorIndex = iColor
    > End With
    >
    > '// Vertical color banding
    > With Range(Target.Offset(1 - Target.Row, 0).Address & ":" &
    > Target.Offset(-1, 0).Address) 'Rows(Target.Row)
    > .FormatConditions.Add Type:=2, Formula1:="TRUE"
    > .FormatConditions(1).Interior.ColorIndex = iColor
    > End With
    >
    > End Sub
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1