Expand on current VBA procedure

pbt

Well-known Member
Joined
Oct 18, 2005
Messages
1,613
Hi folks,

I have the follwing code that will turn the ajoining cell to a particular color based on the Month of a date that is formated 1/12/06.

I need to expand on this code so it will also look at the Year. This spreedsheet will run into the next year so just looking at the month will not do. Of course I would change the color index for the next year to something else.

Code:
Sub ColorByMonth()
    Dim rCell As Range
    Application.ScreenUpdating = False
    Application.Calculate
    On Error GoTo Xit
    For Each rCell In Range("j2:j" & Range("j65536").End(xlUp).Row)
        Select Case Month(rCell)
            Case 1
                rCell.Offset(0, 1).Interior.ColorIndex = 36
            Case 2
                rCell.Offset(0, 1).Interior.ColorIndex = 42
            Case 3
                rCell.Offset(0, 1).Interior.ColorIndex = 39

This continues for all twelve months (Case 12)

Any help would be greatly appreciated.

Thanks
h.h.
 
Yes, I did toggle other sheets before going back to subject sheet and running code.
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Can you just add the following code and run?

Code:
Sub ArrayCheck()
For Each e In MyColor2006
   MsgBox e
Next
End Sub

Again you need to toglle the sheet once before you run the code
 
Upvote 0
Ran the Sub ArrayCheck().

Message box gave me all the numbers in the array each time I clicked OK: (7, 13, 16, 19, 23, 27, 30, 35, 39, 41, 44, 47)

Also did the check on, For Each e In myColorElse:
got (8, 14, 17, 20, 24, 28, 31, 36, 40, 42, 45, 48) with each click

h.h.
 
Upvote 0
bump

Good afternoon to you ( 9:30 PM Thu for me) Jindon (I see you are on line)

Hopeing you have seen my last post.

Macro still not working.

h.h.
 
Upvote 0
Hi

I've just found my typo in the code

check the word "ColorIndex"

one is ColoeIndex and the other one is "ColoIndex"

Those should read as ColorIndex
 
Upvote 0
I did find that and already made the corrections prior to my last test
 
Upvote 0

Forum statistics

Threads
1,221,626
Messages
6,160,909
Members
451,677
Latest member
michellehoddinott

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top