chandelirious
Board Regular
- Joined
- Sep 9, 2004
- Messages
- 84
Hi there Excel Wizards,
I wonder if you can help me with a problem I'm having.
I'm creating a heat map in Excel, and after many months of struggle I've managed to source the code.
When I've put it together in VBA (of which my knowledge is zero), I get a Procedure Too Large message.
I've done some Googling on the issue, and discovered that this should not really happen, that it means that the code is messy. Too right it's messy!
Basically, I have 72 shapes that I need to colour, based on a value in a cell. The shape can be any of 7 colours depending on the value.
This is the code that I have at the moment:
...
This repeats up until ...Shapes("072")...
I've managed to get the code working up until Shape 050, but then the code is too large.
So. Is there any way that I can streamline this code, or perhaps break it down?
I've tried breaking it into Sub Procedures, but either I didn't understand what I was doing or... no, I think I just didn't understand what I was doing.
It's half one in the morning here now, I'm going to bed, so apologies if you reply straight away and I don't, but I will check back here in the morning in case any of you geniuses have got some input for me!
Thanks again, I think you all do a fantastic job here.
I wonder if you can help me with a problem I'm having.
I'm creating a heat map in Excel, and after many months of struggle I've managed to source the code.
When I've put it together in VBA (of which my knowledge is zero), I get a Procedure Too Large message.
I've done some Googling on the issue, and discovered that this should not really happen, that it means that the code is messy. Too right it's messy!
Basically, I have 72 shapes that I need to colour, based on a value in a cell. The shape can be any of 7 colours depending on the value.
This is the code that I have at the moment:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2")) Is Nothing Then
If IsNumeric(Target.Value) Then
If Target.Value < 1 Then
ActiveSheet.Shapes("001").Fill.BackColor.RGB = RGB(255, 255, 255)
ElseIf Target.Value >= 1 And Target.Value < 6 Then
ActiveSheet.Shapes("001").Fill.ForeColor.RGB = RGB(0, 255, 0)
ElseIf Target.Value >= 6 And Target.Value < 10 Then
ActiveSheet.Shapes("001").Fill.ForeColor.RGB = RGB(255, 128, 0)
ElseIf Target.Value >= 10 And Target.Value < 15 Then
ActiveSheet.Shapes("001").Fill.ForeColor.RGB = RGB(255, 64, 0)
ElseIf Target.Value >= 15 And Target.Value < 20 Then
ActiveSheet.Shapes("001").Fill.ForeColor.RGB = RGB(255, 0, 0)
ElseIf Target.Value >= 20 And Target.Value < 25 Then
ActiveSheet.Shapes("001").Fill.ForeColor.RGB = RGB(180, 4, 134)
ElseIf Target.Value >= 25 And Target.Value < 30 Then
ActiveSheet.Shapes("001").Fill.ForeColor.RGB = RGB(132, 132, 132)
Else
ActiveSheet.Shapes("001").Fill.ForeColor.RGB = RGB(0, 0, 0)
End If
End If
End If
If Not Intersect(Target, Range("B3")) Is Nothing Then
If IsNumeric(Target.Value) Then
If Target.Value < 1 Then
ActiveSheet.Shapes("002").Fill.BackColor.RGB = RGB(255, 255, 255)
ElseIf Target.Value >= 1 And Target.Value < 6 Then
ActiveSheet.Shapes("002").Fill.ForeColor.RGB = RGB(0, 255, 0)
ElseIf Target.Value >= 6 And Target.Value < 10 Then
ActiveSheet.Shapes("002").Fill.ForeColor.RGB = RGB(255, 128, 0)
ElseIf Target.Value >= 10 And Target.Value < 15 Then
ActiveSheet.Shapes("002").Fill.ForeColor.RGB = RGB(255, 64, 0)
ElseIf Target.Value >= 15 And Target.Value < 20 Then
ActiveSheet.Shapes("002").Fill.ForeColor.RGB = RGB(255, 0, 0)
ElseIf Target.Value >= 20 And Target.Value < 25 Then
ActiveSheet.Shapes("002").Fill.ForeColor.RGB = RGB(180, 4, 134)
ElseIf Target.Value >= 25 And Target.Value < 30 Then
ActiveSheet.Shapes("002").Fill.ForeColor.RGB = RGB(132, 132, 132)
Else
ActiveSheet.Shapes("002").Fill.ForeColor.RGB = RGB(0, 0, 0)
End If
End If
End If
If Not Intersect(Target, Range("B4")) Is Nothing Then
If IsNumeric(Target.Value) Then
If Target.Value < 1 Then
ActiveSheet.Shapes("003").Fill.BackColor.RGB = RGB(255, 255, 255)
ElseIf Target.Value >= 1 And Target.Value < 6 Then
ActiveSheet.Shapes("003").Fill.ForeColor.RGB = RGB(0, 255, 0)
ElseIf Target.Value >= 6 And Target.Value < 10 Then
ActiveSheet.Shapes("003").Fill.ForeColor.RGB = RGB(255, 128, 0)
ElseIf Target.Value >= 10 And Target.Value < 15 Then
ActiveSheet.Shapes("003").Fill.ForeColor.RGB = RGB(255, 64, 0)
ElseIf Target.Value >= 15 And Target.Value < 20 Then
ActiveSheet.Shapes("003").Fill.ForeColor.RGB = RGB(255, 0, 0)
ElseIf Target.Value >= 20 And Target.Value < 25 Then
ActiveSheet.Shapes("003").Fill.ForeColor.RGB = RGB(180, 4, 134)
ElseIf Target.Value >= 25 And Target.Value < 30 Then
ActiveSheet.Shapes("003").Fill.ForeColor.RGB = RGB(132, 132, 132)
Else
ActiveSheet.Shapes("003").Fill.ForeColor.RGB = RGB(0, 0, 0)
End If
End If
End If
If Not Intersect(Target, Range("B5")) Is Nothing Then
If IsNumeric(Target.Value) Then
If Target.Value < 1 Then
ActiveSheet.Shapes("004").Fill.BackColor.RGB = RGB(255, 255, 255)
ElseIf Target.Value >= 1 And Target.Value < 6 Then
ActiveSheet.Shapes("004").Fill.ForeColor.RGB = RGB(0, 255, 0)
ElseIf Target.Value >= 6 And Target.Value < 10 Then
ActiveSheet.Shapes("004").Fill.ForeColor.RGB = RGB(255, 128, 0)
ElseIf Target.Value >= 10 And Target.Value < 15 Then
ActiveSheet.Shapes("004").Fill.ForeColor.RGB = RGB(255, 64, 0)
ElseIf Target.Value >= 15 And Target.Value < 20 Then
ActiveSheet.Shapes("004").Fill.ForeColor.RGB = RGB(255, 0, 0)
ElseIf Target.Value >= 20 And Target.Value < 25 Then
ActiveSheet.Shapes("004").Fill.ForeColor.RGB = RGB(180, 4, 134)
ElseIf Target.Value >= 25 And Target.Value < 30 Then
ActiveSheet.Shapes("004").Fill.ForeColor.RGB = RGB(132, 132, 132)
Else
ActiveSheet.Shapes("004").Fill.ForeColor.RGB = RGB(0, 0, 0)
End If
End If
End If
If Not Intersect(Target, Range("B6")) Is Nothing Then
If IsNumeric(Target.Value) Then
If Target.Value < 1 Then
ActiveSheet.Shapes("005").Fill.BackColor.RGB = RGB(255, 255, 255)
ElseIf Target.Value >= 1 And Target.Value < 6 Then
ActiveSheet.Shapes("005").Fill.ForeColor.RGB = RGB(0, 255, 0)
ElseIf Target.Value >= 6 And Target.Value < 10 Then
ActiveSheet.Shapes("005").Fill.ForeColor.RGB = RGB(255, 128, 0)
ElseIf Target.Value >= 10 And Target.Value < 15 Then
ActiveSheet.Shapes("005").Fill.ForeColor.RGB = RGB(255, 64, 0)
ElseIf Target.Value >= 15 And Target.Value < 20 Then
ActiveSheet.Shapes("005").Fill.ForeColor.RGB = RGB(255, 0, 0)
ElseIf Target.Value >= 20 And Target.Value < 25 Then
ActiveSheet.Shapes("005").Fill.ForeColor.RGB = RGB(180, 4, 134)
ElseIf Target.Value >= 25 And Target.Value < 30 Then
ActiveSheet.Shapes("005").Fill.ForeColor.RGB = RGB(132, 132, 132)
Else
ActiveSheet.Shapes("005").Fill.ForeColor.RGB = RGB(0, 0, 0)
End If
End If
End If
This repeats up until ...Shapes("072")...
I've managed to get the code working up until Shape 050, but then the code is too large.
So. Is there any way that I can streamline this code, or perhaps break it down?
I've tried breaking it into Sub Procedures, but either I didn't understand what I was doing or... no, I think I just didn't understand what I was doing.
It's half one in the morning here now, I'm going to bed, so apologies if you reply straight away and I don't, but I will check back here in the morning in case any of you geniuses have got some input for me!
Thanks again, I think you all do a fantastic job here.