Macro : Remove Green Color After Run Macro in Second

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all..

i have code to filling mark "V" if cell contains background green color..
i want only the green color background is gone after i run macro in second...
how to make it in macro :
Code:
Sub Checklist_V()Dim cell As Range
Application.ScreenUpdating = False
With ActiveSheet
    For Each cell In .UsedRange
        If cell.Interior.ColorIndex = "14" Then cell.Value = "V"
    Next cell
End With
Application.ScreenUpdating = True
End Sub

any helps much appreciated...
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
This should do the trick:

Code:
Option Explicit
Sub Macro2()

    Dim rngMyCell As Range
    
    Application.ScreenUpdating = False
    
    For Each rngMyCell In ActiveSheet.UsedRange
        If rngMyCell.Interior.ColorIndex = 14 And rngMyCell.Value = "V" Then
            rngMyCell.Interior.Color = xlNone
        End If
    Next rngMyCell
    
    Application.ScreenUpdating = True

End Sub

Note both conditions (an interior colour of 14 and a value of "V" (case sensitive)) have to be met for the background colour to be removed.

HTH

Robert
 
Upvote 0
This should do the trick:

Code:
Option Explicit
Sub Macro2()

    Dim rngMyCell As Range
    
    Application.ScreenUpdating = False
    
    For Each rngMyCell In ActiveSheet.UsedRange
        If rngMyCell.Interior.ColorIndex = 14 And rngMyCell.Value = "V" Then
            rngMyCell.Interior.Color = xlNone
        End If
    Next rngMyCell
    
    Application.ScreenUpdating = True

End Sub

Note both conditions (an interior colour of 14 and a value of "V" (case sensitive)) have to be met for the background colour to be removed.

HTH

Robert

thank you Robert.. i think not yet. the criteria :
1. i filled green color (manually filled) in cell then i run my macro so the result is mark "V" displayed.
2. now, when i click/ run macro again-in second), only background green color is gone not include mark "V"

perhaps..like turn on/off green color background...
 
Last edited:
Upvote 0
So if you want to remove the background colour if its interior colour is 14 regardless if there's a "V" in the cell or not, just change this line of code...

Code:
If rngMyCell.Interior.ColorIndex = 14 And rngMyCell.Value = "V" Then

to this:

Code:
If rngMyCell.Interior.ColorIndex = 14 Then

Robert
 
Upvote 0
So if you want to remove the background colour if its interior colour is 14 regardless if there's a "V" in the cell or not, just change this line of code...

Code:
If rngMyCell.Interior.ColorIndex = 14 And rngMyCell.Value = "V" Then

to this:

Code:
If rngMyCell.Interior.ColorIndex = 14 Then

Robert

hello Robert still not work that my expectation...
your macro make green color is gone only...
i have 2 request :
1. at first, i filled green color (manually filled) and after running my macro mark "V" is displayed;
2. after that using that macro (after modified) , my green color is gone but mark "V" still displayed...

how to join 2 codes in single code,
perhaps, one code can do 2 task..

 
Last edited:
Upvote 0
Try this mod on the code supplied by Trebor76
Code:
Sub Macro2()

    Dim rngMyCell As Range
    
    Application.ScreenUpdating = False
    
    For Each rngMyCell In ActiveSheet.UsedRange
        If rngMyCell.Interior.ColorIndex = 14 And rngMyCell.Value = "V" Then
           [COLOR=#0000ff] rngMyCell.Clear[/COLOR]
        End If
    Next rngMyCell
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
Is this what you're after?
Code:
Sub Checklist_V()

    Dim Cl As Range
    
    Application.ScreenUpdating = False
    With ActiveSheet
        For Each Cl In .UsedRange
            If Cl.Interior.ColorIndex = "14" And Not Cl.Value = "V" Then
                Cl.Value = "V"
            ElseIf Cl.Interior.ColorIndex = "14" And Cl.Value = "V" Then
                Cl.Interior.Color = xlNone
            End If
        Next Cl
    End With
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Is this what you're after?
Code:
Sub Checklist_V()

    Dim Cl As Range
    
    Application.ScreenUpdating = False
    With ActiveSheet
        For Each Cl In .UsedRange
            If Cl.Interior.ColorIndex = "14" And Not Cl.Value = "V" Then
                Cl.Value = "V"
            ElseIf Cl.Interior.ColorIndex = "14" And Cl.Value = "V" Then
                Cl.Interior.Color = xlNone
            End If
        Next Cl
    End With
    Application.ScreenUpdating = True
    
End Sub

Yes...Fluff, thank you very much...its worked well...
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,682
Messages
6,126,195
Members
449,298
Latest member
Jest

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