copy over specific colored cells to another sheet

scubadivingfool

New Member
Joined
Jun 17, 2010
Messages
35
I am using the following code to copy rows from on sheet and make them columns onto another sheet. The code copies every row in the specific sheet however I just need the ones colored in red.


1640635991888.png


VBA Code:
Sub PrintToLargeTags()
   Dim pc As Worksheet 'PriceChange
   Dim lt As Worksheet 'LargeTags
   Dim count_col As Integer
   Dim count_row As Integer
   Dim i As Integer
   Dim j As Integer
   
   
   Set pc = ThisWorkbook.Sheets("PriceChange")
   Set lt = ThisWorkbook.Sheets("LargeTags")
   
   lt.Cells.ClearContents
   pc.Activate
   
   count_col = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlToRight)))
   count_row = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))
   
   For i = 1 To count_col
      For j = 1 To count_row
         lt.Cells(i, j) = pc.Cells(j, i).Text
      
      Next j
   Next i
   
   lt.Activate
   
   
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Perhaps something like this. This check if the pc.Cells(j, i) cell color is red (ColorIndex = 3) and copy. Is that what you wanted?
VBA Code:
Sub PrintToLargeTags()
   Dim pc As Worksheet 'PriceChange
   Dim lt As Worksheet 'LargeTags
   Dim count_col As Integer
   Dim count_row As Integer
   Dim i As Integer
   Dim j As Integer
   
   
   Set pc = ThisWorkbook.Sheets("PriceChange")
   Set lt = ThisWorkbook.Sheets("LargeTags")
   
   lt.Cells.ClearContents
   pc.Activate
   
   count_col = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlToRight)))
   count_row = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))
   
   For i = 1 To count_col
      For j = 1 To count_row
        If pc.Cells(j, i).Interior.ColorIndex = 3 Then
            lt.Cells(i, j) = pc.Cells(j, i).Text
        End If
      Next j
   Next i
   
   lt.Activate
   
   
End Sub
 
Upvote 0
Perhaps something like this. This check if the pc.Cells(j, i) cell color is red (ColorIndex = 3) and copy. Is that what you wanted?
VBA Code:
Sub PrintToLargeTags()
   Dim pc As Worksheet 'PriceChange
   Dim lt As Worksheet 'LargeTags
   Dim count_col As Integer
   Dim count_row As Integer
   Dim i As Integer
   Dim j As Integer
  
  
   Set pc = ThisWorkbook.Sheets("PriceChange")
   Set lt = ThisWorkbook.Sheets("LargeTags")
  
   lt.Cells.ClearContents
   pc.Activate
  
   count_col = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlToRight)))
   count_row = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))
  
   For i = 1 To count_col
      For j = 1 To count_row
        If pc.Cells(j, i).Interior.ColorIndex = 3 Then
            lt.Cells(i, j) = pc.Cells(j, i).Text
        End If
      Next j
   Next i
  
   lt.Activate
  
  
End Sub
OK, almost worked. The only cells that I need on that page do show up but as shown in the image below it doesn't start at A1

1640688883709.png
 
Upvote 0
I was just adding line to your original code. I have no idea what is your lookup range. Maybe you can show your pc and lt sheet?
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

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