Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can i change multiple cells' .Interior.Color at once using an array 1

Status
Not open for further replies.
Apr 14, 2004
13
0
0
NL
Hi,

Building a Bitmap Editor in Excel (which uses a colored cell for every pixel), i can now import 24-bit bitmaps into an Excel sheet. The VBA script does this:

1 read the pixels of the bitmap and put them in an array
2 stretch or shrink the array to 256 cols and enough rows to keep the aspect ratio ok.
3 reduce the palette from 16 million to only 56 colors.
4 color all the cells

The first 3 steps work fine. The problem occurs when arriving at the last step. For some reason i cannot get the interior.color property of an array of cells to be filled at once by an array which stores all the pixel color info.

Any tips?

Thanks. Gijs.

You can find this half baked editor at:
home.1asphost.com/gijsterbeek/bitmapXL.xls
 
Gijs,

How are you trying to do this? Please post your code.

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hi Skip,

Take a look at the web address at the end of Gijs' post - I had a quick look at it last night out of sheer curiosity but I don't have an answer to his question.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
I'm not sure if this will help but perhaps it will get you started. Note that I used a 15 column wide area to correspond to the ColorIndex property. I also defined a range object cel so that you can check other properties while single stepping through the code. You can do it all in one line using the Cells object if you wish. Good Luck!

'Use cel Range object
Sub TestIt()
Dim cel As Range
Dim var As Variant
Dim lngRow As Long, lngCol As Long
var = Range("A1:O10") 'Create 2 dimensional 10x15 array
'Spin array changing the Interior color property
For lngRow = LBound(var, 1) To UBound(var, 1)
For lngCol = LBound(var, 2) To UBound(var, 2)
Set cel = Cells(lngRow, lngCol)
cel.Select 'In case you want to check properties
cel.Interior.ColorIndex = lngCol
Next lngCol
Debug.Print
Next lngRow
Set cel = Nothing
End Sub

'Use Cells object directly
Sub TestIt2()
Dim var As Variant
Dim lngRow As Long, lngCol As Long
var = Range("A1:O10") 'Create 2 dimensional 10x15 array
'Spin array changing the Interior color property
For lngRow = LBound(var, 1) To UBound(var, 1)
For lngCol = LBound(var, 2) To UBound(var, 2)
Cells(lngRow, lngCol).Interior.ColorIndex = lngCol
Next lngCol
Next lngRow
End Sub


Have a great day!

j2consulting@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top