VBA Function code to highlight Odd and Even numbers
Solved/Closed
Kalpesh
-
Apr 13, 2020 at 08:24 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Apr 16, 2020 at 11:57 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Apr 16, 2020 at 11:57 AM
Related:
- Vba code for odd and even numbers
- Battery reset code - Guide
- Www.gameloft.com unlock code ✓ - Phones, PDA & GPS Forum
- Samsung volume increase code - Guide
- Usa country code for whatsapp - Guide
- How to unlock Gameloft games ✓ - Phones, PDA & GPS Forum
2 responses
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Apr 16, 2020 at 11:57 AM
Apr 16, 2020 at 11:57 AM
Hi Kalpesh,
Well then it makes perfect sense to use VBA.
You didn't provide much details, so this is what the code below does:
- Check each cell in column A starting in A1 untill the last cell used.
- The cells will be colored according to your 4 conditions. The colors will be respectively Red, Yellow, Green and Blue.
- The result of the counted colors will be put in the range C1:C4, of which the cells are colored as well for easy reference.
Here is the code:
Let us know if alterations are desired.
Best regards,
Trowa
Well then it makes perfect sense to use VBA.
You didn't provide much details, so this is what the code below does:
- Check each cell in column A starting in A1 untill the last cell used.
- The cells will be colored according to your 4 conditions. The colors will be respectively Red, Yellow, Green and Blue.
- The result of the counted colors will be put in the range C1:C4, of which the cells are colored as well for easy reference.
Here is the code:
Sub RunMe() Dim cRed, cYellow, cGreen, cBlue As Integer For Each cell In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row) If cell.Value < 24 And cell.Value Mod 2 = 1 Then cell.Interior.Color = vbRed cRed = cRed + 1 End If If cell.Value > 24 And cell.Value Mod 2 = 1 Then cell.Interior.Color = vbYellow cYellow = cYellow + 1 End If If cell.Value < 23 And cell.Value Mod 2 = 0 Then cell.Interior.Color = vbGreen cGreen = cGreen + 1 End If If cell.Value > 23 And cell.Value Mod 2 = 0 Then cell.Interior.Color = vbBlue cBlue = cBlue + 1 End If Next cell Range("C1").Value = cRed Range("C1").Interior.Color = vbRed Range("C2").Value = cYellow Range("C2").Interior.Color = vbYellow Range("C3").Value = cGreen Range("C3").Interior.Color = vbGreen Range("C4").Value = cBlue Range("C4").Interior.Color = vbBlue End Sub
Let us know if alterations are desired.
Best regards,
Trowa