VBA code not working

ctorn

New Member
Joined
Nov 5, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
I want my macro to look through each cell in the specified worksheets and then remove the specified fill colors from any of the cells. It is working properly for the first sheet but nothing is happening in the other two sheets. It is running all the way through the code without any errors and I do end up on the Home sheet, but I think I am missing a minor detail -- Any help would be greatly appreciated!

Here is my current code:

VBA Code:
Public Sub Remove_Fill()

Dim SC As Worksheet, RB As Worksheet, Comp As Worksheet, Home As Worksheet
Dim cell As Range

Application.ScreenUpdating = False

Set Home = Sheets("MACROS")
Set SC = Sheets("SC")
Set RB = Sheets("New RB")
Set Comp = Sheets("Comparison")


SC.Select
  
  For Each cell In SC.UsedRange 'Loop through each cell in the ActiveSheet
      If cell.Interior.Color = RGB(255, 255, 0) Then 'Check for a specific fill color
          cell.Interior.Color = xlNone    'Remove Fill Color
      End If
         
      If cell.Interior.Color = RGB(146, 208, 80) Then
        cell.Interior.Color = xlNone
      End If
      
      Application.CutCopyMode = False
        GoTo RB
  Next cell
        
  
RB:
RB.Select
  
  For Each cell In SC.UsedRange 'Loop through each cell in the ActiveSheet
      If cell.Interior.Color = RGB(255, 255, 0) Then 'Check for a specific fill color
          cell.Interior.Color = xlNone    'Remove Fill Color
      End If
         
      If cell.Interior.Color = RGB(146, 208, 80) Then
        cell.Interior.Color = xlNone
      End If
      
      Application.CutCopyMode = False
  Next cell
        GoTo Comp


Comp:
Comp.Select
  For Each cell In SC.UsedRange 'Loop through each cell in the ActiveSheet
      If cell.Interior.Color = RGB(255, 255, 0) Then 'Check for a specific fill color
          cell.Interior.Color = xlNone    'Remove Fill Color
      End If
         
      If cell.Interior.Color = RGB(146, 208, 80) Then
        cell.Interior.Color = xlNone
      End If
      
      Application.CutCopyMode = False
  Next cell
        GoTo Ending

Ending:
Application.ScreenUpdating = True
Home.Select


End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Each of your sections are referring to SC.used range...if you change those so each section references a different range, that should do the trick.
 
Upvote 0
That's a big oof... forgot to change that after copying and pasting hahah thank you!
 
Upvote 0

Forum statistics

Threads
1,215,034
Messages
6,122,782
Members
449,095
Latest member
m_smith_solihull

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