Date question

Makk14

Board Regular
Joined
Mar 5, 2004
Messages
59
Hello experts,

In cell A2 I enter a $ value; in cell B2 I enter a date
In cells C1..N1 I have titles January through December

How would I code the following:
Depending on the date in B2, the value in A2 will be copied to one of the cells in C2…N2? (I don't think I can do this with because of the limitations of how many nested statements can be used)

Thank you!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Maybe a change event:

<font face=Tahoma><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Worksheet_Change(<SPAN style="color:#00007F">ByVal</SPAN> Target <SPAN style="color:#00007F">As</SPAN> Range)
    <SPAN style="color:#00007F">Dim</SPAN> rng <SPAN style="color:#00007F">As</SPAN> Range
         <SPAN style="color:#007F00">'   Only look at single cell changes</SPAN>
        <SPAN style="color:#00007F">If</SPAN> Target.Count > 1 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
        <SPAN style="color:#007F00">'   Set Target Range</SPAN>
        Set rng = Range("B2")
        <SPAN style="color:#007F00">'   Only look at that range</SPAN>
        <SPAN style="color:#00007F">If</SPAN> Intersect(Target, rng) <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
            <SPAN style="color:#007F00">'   Action if Condition(s) are met</SPAN>
            Range("A2").Copy Range("A2").Offset(, Month([B2].Value) + 1)
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,

Smitty
 
Upvote 0
Here's a solution that does not require any code.

In b3 (or this can somewhere out of the way), key formula =month(b2). This will return the month # (1-12) of your date.

In C1:N1, instead of keying the month name, key in an actual date for each month (1/1/06, 2/1/06...12/1/06). Then format these cells as Custom -- mmmm. This shows them as month names again but now they are date values.

In cells C3:N3, use your =month formula again pointed to your month date/names in row 1. Ex. in C3: =month(c1). (again this can be somewhere out of the way or just hidden).

Then in cells C2, key formula: =if(c3=$b3,$a2,0) and copy across to N2.

To test, I keyed $100 in A2, 8/4/06 in B2. The $100 showed up in my August column.
 
Upvote 0
This formula in C2 copied across to N2 (and down to subsequent rows if required)

=IF(TEXT($B2,"mmmm")=C$1,$A2,"")
Book1
ABCDEFG
1januaryfebruarymarchaprilmay
22304-Apr-06   23 
32125-Feb-06 21   
4
Sheet3
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,901
Members
449,097
Latest member
dbomb1414

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