VBA: Summary Sheet based on Tab color

JKast

New Member
Joined
Jul 26, 2011
Messages
21
I have a Summary worksheet that I use to compile data from every worksheet in my workbook. I want to alter my current code to only compile data from worksheets whose tabs are colored Red. The code I'm using is below. The argument I cannot get to work properly seems pretty straightforward, and is highlighted in bold below. I have very little VBA experience, so if somebody could please help me out I'd really appreciate it.

Sub Copy_Sheets()
Dim n As Integer
Dim End_Row As Long
Dim ws As Worksheet
Dim wb As Workbook


For Each ws In Worksheets
If ws.Name <> "Sheet1" And ws.Name <> "Sheet2" And _ ws.Tab.Color = 3 Then
With ws
End_Row = .Range("A65536").End(xlUp).Row
.Range("A2:Ad" & End_Row).Copy Destination:= _
Sheets("Summary").Range("A65536").End(xlUp).Offset(1, 0)
End With
End If
Next ws
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I was able to simply the code and it works using below..

Sub test1()
Dim ws As Worksheet
Dim cell As Range



For Each ws In ThisWorkbook.Worksheets
If ws.Tab.ColorIndex = 3 Then

With ws
End_Row = .Range("A65536").End(xlUp).Row
.Range("A2:Ad" & End_Row).Copy Destination:= _
Sheets("Summary").Range("A65536").End(xlUp).Offset(1, 0)
End With

End If
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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