Hi everyone,
I'm trying to implement some VBA code into my project that will display a red or green up/down arrow based on a certain condition.
My table looks like this:
| Store |
Year |
A Values |
B Values |
C Values |
D Values |
| 1 |
2015 |
0.0 |
0.0 |
1.8 |
2.6 |
| 1 |
2016 |
1.2 |
0.0 |
2.2 |
1.1 |
My current VBA does the following:
- If the Store Number in column 1 matches, the value in columns 3-6 get compared. If the values in 2016 are greater/less than 2015, 2016's cell gets formatted by coloring the cell red or green. My current code is this:
Sub ColorYear()
Dim long1 As Long
Dim rng As Range
Set rng = ActiveSheet.Range("A:A")
long1 = Application.WorksheetFunction.CountA(rng)
For t = 2 To long1
If ActiveSheet.Range("A" & t).Value = ActiveSheet.Range("A" & t - 1).Value Then
If ActiveSheet.Range("C" & t).Value < ActiveSheet.Range("C" & t - 1).Value Then
ActiveSheet.Range("C" & t).Interior.Color = RGB(0, 255, 0)
ElseIf ActiveSheet.Range("C" & t).Value > ActiveSheet.Range("C" & t - 1).Value Then
ActiveSheet.Range("C" & t).Interior.Color = RGB(255, 0, 0)
End If
If ActiveSheet.Range("D" & t).Value < ActiveSheet.Range("D" & t - 1).Value Then
ActiveSheet.Range("D" & t).Interior.Color = RGB(0, 255, 0)
ElseIf ActiveSheet.Range("D" & t).Value > ActiveSheet.Range("D" & t - 1).Value Then
ActiveSheet.Range("D" & t).Interior.Color = RGB(255, 0, 0)
End If
If ActiveSheet.Range("E" & t).Value < ActiveSheet.Range("E" & t - 1).Value Then
ActiveSheet.Range("E" & t).Interior.Color = RGB(0, 255, 0)
ElseIf ActiveSheet.Range("E" & t).Value > ActiveSheet.Range("E" & t - 1).Value Then
ActiveSheet.Range("E" & t).Interior.Color = RGB(255, 0, 0)
End If
If ActiveSheet.Range("F" & t).Value < ActiveSheet.Range("F" & t - 1).Value Then
ActiveSheet.Range("F" & t).Interior.Color = RGB(0, 255, 0)
ElseIf ActiveSheet.Range("F" & t).Value > ActiveSheet.Range("F" & t - 1).Value Then
ActiveSheet.Range("F" & t).Interior.Color = RGB(255, 0, 0)
End If
End If
Next t
End Sub
What I'd like to do is instead of just coloring the cell red/green, I'd like to implement the colored up/down arrow icons. I have no idea how to write this out though, so I was hoping for some assistance.