Populate cell based on other cells

dgaller

New Member
Joined
Apr 23, 2009
Messages
28
I am trying to organize some data given to me using excel 2007. I have a spread sheet with basically 14 columns. Store,Month,Jan,Feb,Mar,Apr,may...

What I would like to do is populate the month column based on the other columns in a row that has data. i.e If the Feb Column has data put Feb in the month column. (only one column will be populated accross the months)

On a small scale I can use an If statement that works if(c3<>"","Jan",if(c4<>"","Feb" etc. but I cannot do all 12 months this way. I am only allowed so many if statements.

Is there another formula or code I can use for this?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi, here is a simplistic answer to your problem. Please replace the ranges with the relevant ones. It will only return the name of the month of the first column with data in, however you can replace the i = Empty with the relevant condition and if necessary swap the action with the else action. Anyway, I hope it can be of some use and avoid having potentially thousands of formulas on your sheet. One other thing is it currently will stop when there is a break in the data in column A, you may need to readjust the looping parameters if that is an issue.

Code:
Sub get_month()
Dim i, j, k As Integer
    Range("A1").Select
k = Selection.CurrentRegion.Rows.Count
    Range("C2").Select
    j = ActiveCell.Row
        Do While Range("A" & j) <> ""
            i = ActiveCell.Value
            j = ActiveCell.Row
                If i = Empty Then
                    ActiveCell.Offset(0, 1).Select
                    Else: Range("B" & j).Value = ActiveCell.Offset(-j + 1, 0).Value
                    Range("C" & j + 1).Select
                End If
        Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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