I have an Excel Spreadsheet which reports upon weekly performance. One portion of the worksheet looks at week over week increases/decreases. I've placed a number of image controls (15 in Total) next to cells which calculate week over week change. The image controls simply display an image depending on whether the value of the adjacent cell is positive or negative.
So, here is where I'm going with it:
As you can see, this is pretty simple. What I'd like to do is find a way to loop through all 15 controls and avoid having 15 IF statements run on the Worksheet_Change() event. The cells containing the week over week values are all in the same column, but not continuous. Involved cells are: ("J26", "J27", "J33", "J34", "J35", "J36", "J37", "J38", "J39", "J40", "J42", "J43", "J44", "J45", "J46")
How does one assign different types to the same array? The above, of course, spits out a type error when using the 'img' variable.
Anyone have any insight into how best to accomplish this?
Thanks in advance.
So, here is where I'm going with it:
Code:
Dim loopme(15, 1) As Variant loopme(0, 0) = "J26" loopme(0, 1) = "Image1" loopme(1, 0) = "J27" loopme(1, 1) = "Image2" loopme(2, 0) = "J33" loopme(2, 1) = "Image3" For x = 0 To 15 cell = loopme(x, 0) img = loopme(x, 1) If Range(cell).Value > 0 And IsNumeric(Range(cell).Value Then img.Picture = LoadPicture("C:\path\to\up_arrow.gif") ElseIf Range(cell).Value < 0 And IsNumeric(Range(cell).Value Then img.Picture = LoadPicture("C:\path\to\down_arrow.gif") Else img.Picture = LoadPicture("") End If Next x</pre>
As you can see, this is pretty simple. What I'd like to do is find a way to loop through all 15 controls and avoid having 15 IF statements run on the Worksheet_Change() event. The cells containing the week over week values are all in the same column, but not continuous. Involved cells are: ("J26", "J27", "J33", "J34", "J35", "J36", "J37", "J38", "J39", "J40", "J42", "J43", "J44", "J45", "J46")
How does one assign different types to the same array? The above, of course, spits out a type error when using the 'img' variable.
Anyone have any insight into how best to accomplish this?
Thanks in advance.
Last edited: