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 IamaSherpa 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.

Happy2cu

Technical User
Feb 9, 2003
5
NZ
The Subs testit and testit2 are great, I have searched the net for months it does exacty what I want but not quite. Looking for the same as but as Function that i can call as i loop thru my sub I have a array, rowno, colno, to pass too it my array is "A1,J9" 10 cols X 9 rows 90 numbers and increment my rows by array(x) Mod 10 = 0.I do hope i have explained myself well enough any help will be gratful.

Happy2CU

 
>The Subs testit and testit2

What subs will those be, then?
 
They are on this site do a search for testit.scroll down to same heading as mind.
 
Wait, seriously? You expect us to search in order to be able to offer you help?
 
Sorry for that my first post on here. I think you need this to fin those subs thread707-846266
 
No problem. So, now we have our starting reference … :)

>I do hope i have explained myself well enough
Not quite sure you have. For me, anyway (no idea what you are trying to say with "increment my rows by array(x) Mod 10 = 0". So, I'll assuming you want to colour the whole range (which might change during your loop) a specific colour:

Code:
[blue]Public Sub Example()
    TestIt2 Range("A1:J9"), vbRed
End Sub

[green]'Use Cells object directly[/green]
Sub TestIt2(srcRange As Range, NewColor As Long)
Dim var As Variant
Dim lngRow As Long, lngCol As Long
   var = srcRange [green]'Create 2 dimensional 10x15 array[/green]
   [green]'Spin array changing the Interior color property[/green]
   For lngRow = LBound(var, 1) To UBound(var, 1)
      For lngCol = LBound(var, 2) To UBound(var, 2)
         Cells(lngRow, lngCol).Interior.Color = NewColor
      Next lngCol
   Next lngRow
End Sub[/blue]

However, given that TestIt and testit2 were designed as examples for colouring different columns as different colours, a more efficient version for your requirement (assuming I have even vaguely understood it) is:

Code:
[blue]Sub TestIt3(srcRange As Range, NewColor As Long)
    srcRange.Interior.Color = NewColor
End Sub[/blue]

 
Thank You StrongM for you replies and code.
I have since butchered Testit2 Sub example into a Function and call it on each loop with a small bit of code to get correct rows and cols to send to function my bits of code below. This is all working OK for me now you been a great help along the way thanks.

ShowMeTwo = ShowMeTwo + 1 'is a static var incremented each loop of 1 to 90 when row is 10 the col increases by 1
If ShowMeTwo < 11 Then
ArrRow = ArrRow
ArrCol = ArrCol + 1
Else
ArrRow = ArrRow + 1
ShowMeTwo = 1
ArrCol = 1
End If
'var is empty and needs to be change

y = ColorArrayCell(var, ArrRow, ArrCol)

Function ColorArrayCell(var, lngRow, lngCol)
Dim cel As Range
Worksheets("Called Numbers").Activate

var = Range("A1:J9")
Set cel = Cells(lngRow, lngCol)
cel.Select 'In case you want to check properties
cel.Interior.ColorIndex = 4
Worksheets("Bingo").Activate
End Function
 
> butchered Testit2 Sub example into a Function

You haven't, you know, not really. At least, not from the code you show here. You may have called ColorArrayCell a function, but you are using it as a procedure.

Glad you've got something working - but I'm not sure why you'd rather colour in an entire range cell by cell (which is what you are doing) rather than the whole range in one go.
 
I color each cell to be able to go back and see which numbers have been last drawn and there order.
Thanks again for all your support.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top