Help needed! to check for presence of cell color

fountainwood

New Member
Joined
Jun 15, 2008
Messages
10
I need help here!
I want to create some code that checks all the cells in a row to find if any cell has a background color and if it finds any colored cell, to then set the first column of that row to that color.

desperate!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
This is for row 1, change as necessary:

Code:
Sub test()
Dim c As Range
For Each c In Range("A1", Cells(1, Columns.Count))
    If c.Interior.ColorIndex <> xlNone Then
        Range("A1").Interior.ColorIndex = c.Interior.ColorIndex
        Exit For
    End If
Next
End Sub
 
Upvote 0
I had thought of that, but how you would look for any color, rather than a specific one? That's why I looped.
 
Upvote 0
If you are on XL2003 or prior, there are 65536 rows, do you really need to check that many, or is there a smaller range you need to check?
 
Upvote 0
Are there specific colors which would be used? If there are say 5 color possibilities, it would save you a lot of time...

What happens if there is more than one colored cell in a row?
 
Upvote 0
Code:
Sub Test()
Dim c As Range
For Each c In Sheet1.UsedRange
If c.Interior.ColorIndex <> xlNone Then Cells(c.Row, 1).Interior.ColorIndex = c.Interior.ColorIndex
Next c
End Sub

lenze
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,216
Members
448,876
Latest member
Solitario

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