Help - Search - Members - Calendar
Full Version: VBA - a question
BleepingComputer.com > Software > Programming
   
espinet
Hi everyone,

I hope someone can help me doing this: I would like to take a drawing (for example some polygonal shape) with grid inside (not necessarily square elements), and after that I would like to colour in each different cell individually. Can anybody tell me whether it is possible to colour in each cell according to an Excel table using VBA?? huh.gif

Sorry I know it is not very clear, but if you need me to further clarify I'll be happy to do it.

Thanks in advance,

espinet
tos226
Not completely clear to me sad.gif
But I'll take a guess and possibly provide few hints how to go about it.

I presume your polygon will be in front of excel grid and you want to color the grid and you have a lookup table in excel to select the color based on some business rule in your polygon.

Let's say you already have the color value looked up. On to the color syntax:

If a cell is selected, the syntax would be
Selection.Interior.ColorIndex = someNumber 0,255,37…

If not selected, you could address, in a loop or individually, each cell you want to colour, generally using a syntax such as
range("B2").interior.colorIndex=55

You can try recording a macro for the entire process, pickup the syntax from there, then modify it for some flexibility, i.e. not fixed cell addresses.

Recording is the best way, anyway, especially that in the UK it just might read ColourIndex smile.gif
Once you record, F1 over VBA keywords takes you to help which explains what you recorded in great detail and then you can make Excel sing.

Edited after rereading your post, and guessing some more:
You might be asking about coloring the polygon itself, i.e. my guesses are incorrect. If so, I can't give you an answer quickly, because it will involve addressing drawing objects in VBA rather than Excel ranges. Someone else would need to jump in if that's the case.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.