Conditional Formatting in cells

dshafique

Board Regular
Joined
Jun 19, 2017
Messages
171
Hi Guys, having an issue where I cant copy and paste cells that have conditional formatting to different worksheets. I have it where a cell will be green if above a reference value, and red if it falls below, but turns white when i paste it into a different worksheet. and i get an error about copying formatted cells.
 
thanks for the code, so is there a way to use this where it selects the cell by table references instead of having the user input? its a dynamic sheet where data changes per month. so the code i used to select it dynamically is

Code:
Range("TableAll[[#Headers],[Fiscal YTD]]").Select
    ActiveCell.offset(1,1).select
    Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).Select

the header on the right of Fiscal YTD is some month which is new each month. so the idea is that it selects the cells below the column to the right, all the way to the end of the table and formats them.

is there a way to mix the two codes together?

(sorry im new to vba, as you can probably tell)
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Sorry for the delayed response - I had to do some research on how to handle this.

Give this a shot:

Code:
Public Sub CopyPaste()
Dim srng        As Range, _
    drng        As Range, _
    rrng        As Range

Range("TableAll[[#Headers],[Fiscal YTD]]").Offset(1, 1).Select
Set srng = Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column))
Set drng = Application.InputBox("Please select the cell you want to paste the range into", Type:=8)

For Each rrng In srng
    With drng.Offset(rrng.Row - srng(1).Row, rrng.Column - srng(1).Column)
        .Value = rrng.Value
        .Interior.ColorIndex = rrng.DisplayFormat.Interior.ColorIndex
    End With
Next rrng

End Sub
 
Upvote 0
Thanks MrKowz, sorry for the late response, it was the weekend, so i didnt get a chance to try it out. Everything works great! I changed one line so it could choose it dynamically

Code:
Dim srng        As Range, _
    drng        As Range, _
    rrng        As Range


Range("TableAll[[#Headers],[Fiscal YTD]]").Offset(1, 1).Select
Set srng = Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column))
Set drng = Range("TableAll[[#Headers],[Fiscal YTD]]").Offset(1, 1)




For Each rrng In srng
    With drng.Offset(rrng.Row - srng(1).Row, rrng.Column - srng(1).Column)
        .Value = rrng.Value
        .Interior.ColorIndex = rrng.DisplayFormat.Interior.ColorIndex
    End With
Next rrng

when i copy and paste it to a different worksheet, the green turns to teal, and the red turns bright.

so the greens go from 0, 176, 80 (RGB) to 0, 128, 128.

and the reds go from 192, 0, 0 to 255, 0, 0 with black text instead of white text.

i dont care about the text color, but do you know why it would change the colors like that?
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,664
Members
448,976
Latest member
sweeberry

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