Conditional Formatting Scuppers Macro

rb3883

New Member
Joined
Nov 23, 2008
Messages
24
I have the following Macro (below) copies red cells and pastes special however when the cells are red by conditional formatting it doesn't work, is there a way around this? Are all conditional formatting not picked up by the cell properties?

My Code is

Sub colourtest()
Dim Cell As Range
For Each Cell In Selection
If Cell.Interior.ColorIndex = 3 Then
Cell.Copy
Cell.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End If
Next Cell

End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi Jim,

Thanks very much for your quick response.

Code now altered as below however I got the error:

Run-time error '1004':
Unable to get the color index property of the interiror class?

Any ideas? It seems like you're pointing me in the right direction though!

Thanks for your time, Ryan


Sub colourtest()
Dim Cell As Range
For Each Cell In Selection
If Cells.FormatConditions(1).Interior.ColorIndex = 3 Then
Cell.Copy
Cell.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End If
Next Cell

End Sub
 
Upvote 0
I have the following Macro (below) copies red cells and pastes special however when the cells are red by conditional formatting it doesn't work, is there a way around this? Are all conditional formatting not picked up by the cell properties?

My Code is

Sub colourtest()
Dim Cell As Range
For Each Cell In Selection
If Cell.Interior.ColorIndex = 3 Then
Cell.Copy
Cell.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End If
Next Cell

End Sub
Could you just use the same condition(s) in your nacro, that you have in the Conditional Formatting?
 
Upvote 0
Thanks Andrew and Peter both good solutions i'm sure I can solve this now. Your time is much appreciated.

Have a nice weeekend, Ryan
 
Upvote 0
Ryan,
Thought I'd share some further understanding I got from your issue. Maybe it can benefit you in solving your issue. First my original post was Cells.FormatConditions(1),...
when it should have been Cell.FormatConditions(1)... That however is a mute point because I discovered that in the course of Testing/looping through -- if there is No conditional formatting entered for a current cell under examination Excel raises a 1004 Error.

So I added the line On Error Resume Next
and the Line
If Err.Number > 0 Then
Else

thereby getting around it - So here's where I finished up...

Code:
Sub colourtest()
Dim Cell As Range
For Each Cell In Selection
On Error Resume Next
If Cell.FormatConditions(1).Interior.ColorIndex = 3 Then
If Err.Number > 0 Then
Else
MsgBox "Found C/F # 3 in Cell " & Cell.Address  'maybe replace this line with the 4 lines
                                                               'below that are currently commented out
End If
'Cell.Copy
'Cell.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
'xlNone, SkipBlanks:=False, Transpose:=False
'Application.CutCopyMode = False
End If
Next Cell
End Sub

Good Luck,

Jim
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top