macro copy condition format colours

ste33uka

Active Member
Joined
Jan 31, 2020
Messages
473
Office Version
  1. 365
Platform
  1. Windows
Hi could anyone change or add to the following macro
I would like it to also copy the cell colours which are created by condition format, but not copy the rules, just the colours
VBA Code:
Sub Copy_to_book()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim i As Long
    Dim lastRow As Long

    For i = 1 To 101
        With Sheets(CStr(i))
            If LCase(.Range("vZ2").Value) = "yes" Then
                lastRow = Workbooks("Book1").Sheets("CARDS").Cells(Rows.Count, "A").End(xlUp).Row + 1

                Workbooks("Book1").Sheets("CARDS").Range("A" & lastRow & ":ET" & lastRow + 74).Value = .Range("A1:ET75").Value
            End If
        End With
    Next i

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Give this a try. Cannot test without your file, but I tested on a simpler test file.
Rich (BB code):
Sub Copy_to_book()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim i As Long
    Dim lastRow As Long
    Dim f As Long

    For i = 1 To 101
        With Sheets(CStr(i))
            If LCase(.Range("vZ2").Value) = "yes" Then
                lastRow = Workbooks("Book1").Sheets("CARDS").Cells(Rows.Count, "A").End(xlUp).Row + 1

                Workbooks("Book1").Sheets("CARDS").Range("A" & lastRow & ":ET" & lastRow + 74).Value = .Range("A1:ET75").Value
                For f = 1 To .Range("A1:ET75").Count
                   Workbooks("Book1").Sheets("CARDS").Range("A" & lastRow & ":ET" & lastRow + 74)(f).Interior.Color = .Range("A1:ET75")(f).DisplayFormat.Interior.Color
                Next f


            End If
        End With
    Next i

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 1
Solution
Give this a try. Cannot test without your file, but I tested on a simpler test file.
Rich (BB code):
Sub Copy_to_book()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim i As Long
    Dim lastRow As Long
    Dim f As Long

    For i = 1 To 101
        With Sheets(CStr(i))
            If LCase(.Range("vZ2").Value) = "yes" Then
                lastRow = Workbooks("Book1").Sheets("CARDS").Cells(Rows.Count, "A").End(xlUp).Row + 1

                Workbooks("Book1").Sheets("CARDS").Range("A" & lastRow & ":ET" & lastRow + 74).Value = .Range("A1:ET75").Value
                For f = 1 To .Range("A1:ET75").Count
                   Workbooks("Book1").Sheets("CARDS").Range("A" & lastRow & ":ET" & lastRow + 74)(f).Interior.Color = .Range("A1:ET75")(f).DisplayFormat.Interior.Color
                Next f


            End If
        End With
    Next i

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub
Thanks alot bud, works great

 
Upvote 0
Hi ,
Try this:
VBA Code:
Sub Copy_to_book()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim i As Long
    Dim lastRow As Long

    For i = 1 To 101
        With Sheets(CStr(i))
            If LCase(.Range("vZ2").Value) = "yes" Then
                lastRow = Workbooks("Book1").Sheets("CARDS").Cells(Rows.Count, "A").End(xlUp).Row + 1
                For m = lastRow To lastRow + 74
                 k = k + 1
                    For n = 1 To 150
                        Workbooks("Book1").Sheets("CARDS").Cells(m, n).Value = .Cells(k, n).Value
                        Workbooks("Book1").Sheets("CARDS").Cells(m, n).Interior.Color = .Cells(k, n).DisplayFormat.Interior.Color
                        
                     Next
                Next
            End If
        End With
    Next i
End Sub
 
Upvote 0
Hi ,
Try this:
Did you test that? I tried the same thing and it just used the color value 0 to copy to all other cells, rather than copying from each corresponding cell. That's why I did the loop.
 
Upvote 0
Did you test that? I tried the same thing and it just used the color value 0 to copy to all other cells, rather than copying from each corresponding cell. That's why I did the loop.
Yes tested it and works! Cheers
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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