Deleting color from 2 worksheets

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
I need to delete color from 2 sheets with the same command button.
How is this possible with my code?


VBA Code:
         Private Sub Delete_Color()

                Dim ws As Worksheet
                Dim rng As Range
                
                For Each ws In ThisWorkbook.Worksheets.Count
    
            If ws.Name <> Trim("Job Card Master") Then
            ws.Range("A13:Q61").Cells.Interior.Color = xlNone
            ws.Range("A66:Q122").Cells.Interior.Color = xlNone
            ws.Range("A127:Q183").Cells.Interior.Color = xlNone
            ws.Range("A188:Q244").Cells.Interior.Color = xlNone
            ws.Range("A249:Q299").Cells.Interior.Color = xlNone
                rng.Font.ColorIndex = 1
                rng.Font.Italic = False
                rng.Font.Bold = False
            End If
            
       If ws.Name <> Trim("Job Card with Time Analysis") Then
            ws.Range("A13:Q61").Cells.Interior.Color = xlNone
            ws.Range("A66:Q122").Cells.Interior.Color = xlNone
            ws.Range("A127:Q183").Cells.Interior.Color = xlNone
            ws.Range("A188:Q244").Cells.Interior.Color = xlNone
            ws.Range("A249:Q299").Cells.Interior.Color = xlNone
                rng.Font.ColorIndex = 1
                rng.Font.Italic = False
                rng.Font.Bold = False
            End If
      Next ws
  

              End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
What are the names of the two sheets?
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Delete_Color()
   
   Dim ws As Worksheet
   Dim rng As Range
   
   For Each ws In ThisWorkbook.Worksheets(Array("Job Card Master", "Job Card with Time Analysis"))
      ws.Range("A13:Q61").Cells.Interior.Color = xlNone
      ws.Range("A66:Q122").Cells.Interior.Color = xlNone
      ws.Range("A127:Q183").Cells.Interior.Color = xlNone
      ws.Range("A188:Q244").Cells.Interior.Color = xlNone
      ws.Range("A249:Q299").Cells.Interior.Color = xlNone
   Next ws
End Sub
 
Upvote 0
Solution
Thanks for that works a treat

This is similar but for filling color?
How could I alter it to fill both sheets?

VBA Code:
Sub colorAbove(rng As Range)
    Dim i As Long, rrg As Range
    Dim ws As Worksheets
   
For Each ws In ThisWorkbook.Worksheets(Array("Job Card Master", "Job Card with Time Analysis"))

    For i = 1 To rng.Rows.Count
        Set rrg = rng.Rows(i)
 
        If WorksheetFunction.CountA(rrg) = 0 Then
           
            If rrg.Offset(1).Cells(3) <> "" Then
               
                rrg.Interior.ColorIndex = 36
            End If
        End If
    Next i
    Next ws
End Sub
 
Upvote 0
As this is a totally different question, it needs a new thread.
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,554
Members
448,970
Latest member
kennimack

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