VBA - Copy All Cells Highlighted from Conditional Formatting to Another Sheet

luckee

New Member
Joined
Sep 23, 2022
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
Hi, I have a workbook with over 20 sheets. AA1, AA2, AA3, AA4, etc with all the same headings. I have conditionally formatted cells to highlight RGB (180,198,231) if certain words are found in column F.

I want to create a macro that will go through all the sheets and find all the conditionally formatted rows then copy only columns F and AR from those sheets to a new consolidated sheet.

I'm not sure how to do this, macro newbie.

Thanks in advance!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Check if this macro works for you:

VBA Code:
Sub Macro_consolidate_by_color()
  Dim sh As Worksheet, shC As Worksheet
  Dim i As Long, k As Long
 
  Set shC = Sheets("consolidate")   'fit to your consolidate sheet name
  k = 1 
  For Each sh In Sheets
    If sh.Name <> shC.Name Then
      For i = 1 To sh.Range("F" & Rows.Count).End(3).Row
        If sh.Range("F" & i).DisplayFormat.Interior.Color = 15189684 Then
          k = k + 1
          shC.Range("F" & k).Resize(1, 39).Value = sh.Range("F" & i).Resize(1, 39).Value
        End If
      Next
    End If
  Next
End Sub

Note: If the macro doesn't work, then you should put the formula you use for conditional formatting here. And a couple of examples.

🧙‍♂️
 
Upvote 0
Check if this macro works for you:

VBA Code:
Sub Macro_consolidate_by_color()
  Dim sh As Worksheet, shC As Worksheet
  Dim i As Long, k As Long
 
  Set shC = Sheets("consolidate")   'fit to your consolidate sheet name
  k = 1
  For Each sh In Sheets
    If sh.Name <> shC.Name Then
      For i = 1 To sh.Range("F" & Rows.Count).End(3).Row
        If sh.Range("F" & i).DisplayFormat.Interior.Color = 15189684 Then
          k = k + 1
          shC.Range("F" & k).Resize(1, 39).Value = sh.Range("F" & i).Resize(1, 39).Value
        End If
      Next
    End If
  Next
End Sub

Note: If the macro doesn't work, then you should put the formula you use for conditional formatting here. And a couple of examples.

🧙‍♂️
Hi DanteAmor, thanks for the code ! it works to copy and paste the highlighted rows. is there a way to only copy and paste specific columns column F and column I (not everything starting from column F) and starting from cell B2 of the "consolidate" tab instead of F2?

thanks again !
 
Upvote 0
copy and paste specific columns column F and column I (not everything starting from column F) and starting from cell B2 of the "consolidate" tab instead of F2?

Try:

VBA Code:
Sub Macro_consolidate_by_color()
  Dim sh As Worksheet, shC As Worksheet
  Dim i As Long, k As Long
  
  Set shC = Sheets("consolidate")   'fit to your consolidate sheet name
  
  k = 1
  For Each sh In Sheets
    If sh.Name <> shC.Name Then
      For i = 1 To sh.Range("F" & Rows.Count).End(3).Row
        If sh.Range("F" & i).DisplayFormat.Interior.Color = 15189684 Then
          k = k + 1
          shC.Range("B" & k).Value = sh.Range("F" & i).Value
          shC.Range("C" & k).Value = sh.Range("I" & i).Value
        End If
      Next
    End If
  Next
End Sub

😇
 
Upvote 0
Solution
Try:

VBA Code:
Sub Macro_consolidate_by_color()
  Dim sh As Worksheet, shC As Worksheet
  Dim i As Long, k As Long
 
  Set shC = Sheets("consolidate")   'fit to your consolidate sheet name
 
  k = 1
  For Each sh In Sheets
    If sh.Name <> shC.Name Then
      For i = 1 To sh.Range("F" & Rows.Count).End(3).Row
        If sh.Range("F" & i).DisplayFormat.Interior.Color = 15189684 Then
          k = k + 1
          shC.Range("B" & k).Value = sh.Range("F" & i).Value
          shC.Range("C" & k).Value = sh.Range("I" & i).Value
        End If
      Next
    End If
  Next
End Sub

😇
that's perfect, thank you so much !
 
Upvote 1

Forum statistics

Threads
1,223,103
Messages
6,170,123
Members
452,303
Latest member
c4cstore

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