Closed Thread
Results 1 to 4 of 4

Month to number

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-16-2006
    Posts
    349

    Month to number

        Range("AT2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(RC1=""JAN"",1,IF(RC1=""FEB"",2,IF(RC1=""MAR"",3,IF(RC1=""APR"",4,IF(RC1=""MAY"",5,IF(RC1=""JUN"",6,0))))))"
        Range("AU2").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(RC1=""JUL"",7,IF(RC1=""AUG"",8,IF(RC1=""SEP"",9,IF(RC1=""OCT"",10,IF(RC1=""NOV"",11,IF(RC1=""DEC"",12,0))))))"
    this code above looks at cell a1 to see what month it is then gives it the corresponding number ie jan = 1 , feb = 2 and so on, the code has been wrote in 2 cells, at2 calculates jan to jun and au2 calculates jul to dec

    how can i put these in on cell, so that at2 looks at a1 and decides if it is 1 2 3 4 5 6 7 8 9 10 11 or 12

  2. #2
    Forum Contributor WinteE's Avatar
    Join Date
    04-07-2007
    Location
    Netherlands
    Posts
    544
    Try this :

    Select Case Range("A1").Value
       Case "Jan"
          Range("AT2").Value = 1
       Case "Feb"
          Range("AT2").Value = 2
       Case "Mar"
          Range("AT2").Value = 3
    ....
    End Select
    Erik
    Just keep it simple !


    http://www.excelguide.eu
    In English as well as in Dutch

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719
    Do you need to use a macro? If so

        Range("AT2").Select
        ActiveCell.FormulaR1C1 = "=IF(R[-1]C[-45]="""","""",MONTH(""1 ""&R[-1]C[-45]))"
    or just use a formula in AT2

    =IF(A1="","",MONTH("1 "&A1))

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    khalid79m

    Please read forum rules - see links below

    Closing duplicate threads
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1