Turning a coloured cell into a number

laniw75

New Member
Joined
Dec 18, 2010
Messages
15
Good afternoon, my learned friends.

I need some vba (or a conditional formatting formula) to add a 1 into all the cells that are red. Can anyone assist.

Thanks in advance :)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You can't change the contents of a cell using conditional formatting - that can only change its formatting.

The following code goes through every cell in the active sheet and if the background colour is red, it wil add one to its value:-
Code:
Option Explicit
 
Sub AddOneToRedCells()
 
  Dim oCell As Range
 
  For Each oCell In ActiveSheet.UsedRange
    If oCell.Interior.Color = vbRed Then oCell = oCell.Value + 1
  Next oCell
 
End Sub

When say "add a 1 into", do you mean "put 1 into" or "add 1 to". I've assumed the latter but I'm sure you can modify the line in question if you actually want the former.
 
Last edited:
Upvote 0
Hi R,

Thanks for you help. I am still having some issues. The background colour is actually a pink which I have adjusted in the code and although there are no errors when I run the macro, the pinks aren't entering a 1. Here is a copy of the exact code I am using, can you see where I am going wrong? The cells are blank apart from the formatting.

Option Explicit

Sub AddOneToRedCells()

Dim oCell As Range

For Each oCell In ActiveSheet.UsedRange
If oCell.Interior.Color = RGB(255, 153, 153) Then oCell = oCell.Value + 1
Next oCell

End Sub
 
Upvote 0
It works fine for me!

Are you sure you have the color right?

Did you set the color yourself to the RGB? That's what I did and it works fine.

Code:
Sub AddOneToRedCells()
    Dim oCell As Range
    For Each oCell In ActiveSheet.UsedRange
        If oCell.Interior.Color = RGB(255, 153, 153) Then oCell = oCell.Value + 1
    Next oCell
End Sub
 
Upvote 0
Hi Jeff,

I just ran it again and it works beautifully, I still had the vba window open. Thank you so much for you help!

:laugh:
 
Upvote 0
Hi all excel genius's, I have an addendum to this :)

I need the red cell to reformat to general before it overrides with a numeral one.

Some cells have a date in them which just makes my macro add a day!

Option Explicit

Sub AddOneToRedCells()
Dim oCell As Range
For Each oCell In ActiveSheet.UsedRange
If oCell.Interior.Color = RGB(255, 153, 153) Then oCell = oCell.Value + 1
Next oCell
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,572
Members
452,927
Latest member
whitfieldcraig

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