apply the cell value as the fill colour

BFrassek

New Member
Joined
Nov 30, 2015
Messages
6
I have the following question:

Is there a way in VBA for a bigger table (400x400 cells) to apply the value of each cell as the interior colour "at once"?
"At once" means, that I do not need loops to fill the cells which will take a few seconds.

I've tried out something like

Range("A1:OJ400").Interior.Color = Range ("A1:OJ400").value

but will get a "types incompatible" message.

Best regards
Bernd Frassek
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I have the following question:

Is there a way in VBA for a bigger table (400x400 cells) to apply the value of each cell as the interior colour "at once"?
"At once" means, that I do not need loops to fill the cells which will take a few seconds.
Are you filling each cell with the same color... or does each cell get colored differently?

Show us a sample of the values you have in the cells.
 
Upvote 0
Are you filling each cell with the same color... or does each cell get colored differently?

Show us a sample of the values you have in the cells.

Each cell of the table (A1:OJ400) contains a RGB-value (Maximum value 256^3-1).
The purpose is to set the cell Background Color according to the cell's value.
A solution with Loops does this:

For y = 400 To 1 Step -1
For x = 1 To 400 Step 1
Cells(y, x).Interior.color = cells(y,x).value
Next x
Next y

But it is slow; therefore, I asked the question if there is any "at once" solution ...

Best regards
Bernd Frassek (Germany)
 
Upvote 0
You do need a loop, but you can do a faster loop than that.
Reading a block of cells is much faster that a loop reading each one.

Code:
Dim myColors as Variant
Dim I as Long, J As Long

With Range("A1:OJ400")

    myColors = .Value

    For I = 1 to .Rows.Count
        For J = 1 to .Columns.Count
            .Cells(I, j).Interior.Color = myColors(I,j)
        Next j
    Next I

End With
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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