Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default 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.

wrote in message
oups.com...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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

wrote in message
oups.com...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bug in .FormatConditions.Add Type:=xlExpression, Formula1:=cfExpression Thief_ Excel Worksheet Functions 3 April 19th 05 02:26 AM
'Kill' solomon_monkey Excel Programming 7 January 7th 05 09:56 AM
FormatConditions (fails in different Languages) DamiaoBR[_2_] Excel Programming 0 May 12th 04 01:54 AM
VBA code need help on CopyPaste alienscript Excel Programming 5 December 18th 03 04:51 PM
font size on formatconditions Chip Pearson Excel Programming 0 August 13th 03 02:09 PM


All times are GMT +1. The time now is 11:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"