+ Reply to Thread
Results 1 to 10 of 10

Derive Previous Months from User Input

  1. #1
    Registered User
    Join Date
    11-07-2014
    Location
    India
    MS-Off Ver
    2016
    Posts
    88

    Derive Previous Months from User Input

    Hello Friends

    Please help. I want the below answer. How to drieved this using VBA code

    12
    11
    10
    9
    8
    7
    6
    5
    4
    3
    2
    1
    12
    11
    10
    9
    son on...

    Currently I am using below code for this.

    Please Login or Register  to view this content.
    In this case the value will get zero at point 'm3' and then become negative from there.

    Instead I want to reset the value of 12 after zero.

    This is because, I am using this input value to determine the month number and thereby derive the previous 6 months out of it.
    Last edited by Kaustubh1040; 06-15-2019 at 02:58 AM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi, try this !


    As a very beginner starter :

    PHP Code: 
        Dim M%(1 To 5), N%
            
    M(1) = Application.InputBox("Enter Your Month")
        For 
    2 To 5
            M
    (N) = IIf(M(1) = 112M(1) - 1)
        
    Next 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  3. #3
    Registered User
    Join Date
    11-07-2014
    Location
    India
    MS-Off Ver
    2016
    Posts
    88

    Re: Derive Previous Months from User Input

    Thank you so much. You are amazing.

  4. #4
    Registered User
    Join Date
    11-07-2014
    Location
    India
    MS-Off Ver
    2016
    Posts
    88

    Re: Derive Previous Months from User Input

    Need one more help. This is related to this formula only.

    I want to show three month names in three cells. Say, I am using input value 4 then i want to show the month name April, March and February in AH1, AI1 and AJ1 cells. Is there is any way to do this?

    If it is not possible using this code then please let me know. Thank you once again

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,029

    Re: Derive Previous Months from User Input

    How about
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-07-2014
    Location
    India
    MS-Off Ver
    2016
    Posts
    88

    Re: Derive Previous Months from User Input

    Sorry, but I can't user to input the same number twice. I mean in the first (asked initally), the person is already giving the input number.

    Now, based on this input numbers, I want to display the name of last three months in cell AH1, AI1 and AJ1. How this can be done?

    The purpose of this code is :

    Based on the input number I will identify the month and then using the same number I will arrive the vlookup amount in the cell AH2, AI2 and AJ2.

    But, the name of these columns will be based on the input number. If input is 4 then this three cells will be Feb, Mar and Apr and If input number is 3 then these three cells will be Jan, Feb and Mar.


    Is it possible using the first code given by you.
    Please Login or Register  to view this content.
    Sorry, If I am doing something wrong.

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,029

    Re: Derive Previous Months from User Input

    Just add this to the end of your code
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-07-2014
    Location
    India
    MS-Off Ver
    2016
    Posts
    88

    Re: Derive Previous Months from User Input

    Its works only till Jan to Nov. If In case I add 11 in the input box then my months name would be Nov, Dec and Jan. But instead giving these names it is giving me error. It seems that it is not getting reset after 1 or 12.

    Please help.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,464

    Re: Derive Previous Months from User Input

    Quote Originally Posted by Kaustubh1040 View Post
    I want to show three month names in three cells. Say, I am using input value 4 then i want to show the month name April, March and February in AH1, AI1 and AJ1 cells. Is there is any way to do this?
    Please Login or Register  to view this content.
    Last edited by jindon; 06-16-2019 at 02:12 AM.

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb

    Quote Originally Posted by Kaustubh1040 View Post
    If input is 4 then this three cells will be Feb, Mar and Apr and If input number is 3 then these three cells will be Jan, Feb and Mar.Is it possible using the first code given by you.
    A demonstration as a beginner starter :

    PHP Code: 
    Sub Demo()
        
    Dim M%(1 To 5), N%
            
    M(1) = Application.InputBox("Enter Your Month")
            [
    AH1].Value2 MonthName(M(1))
        For 
    2 To 5
            M
    (N) = IIf(M(1) = 112M(1) - 1)
            If 
    4 Then Cells(33 N).Value2 MonthName(M(N))
        
    Next
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » !

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Previous 6 Months Value and use in Sum If Formula taking input variable
    By Kaustubh1040 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2019, 01:35 PM
  2. Replies: 3
    Last Post: 11-15-2018, 03:48 PM
  3. [SOLVED] Having user input and a formula (that can incorporate the user input) in the same cell.
    By Super_Bob in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-21-2018, 05:55 AM
  4. Replies: 4
    Last Post: 05-18-2016, 02:37 PM
  5. [SOLVED] Add additional days/weeks/months based on user input
    By pauldaddyadams in forum Excel General
    Replies: 3
    Last Post: 12-09-2015, 01:29 PM
  6. Autofill Months Based on User Input
    By jalex627 in forum Excel General
    Replies: 1
    Last Post: 07-08-2014, 03:24 PM
  7. [SOLVED] Find last previous non blank value and summarise previous 6 months
    By Lady_Shaz in forum Excel General
    Replies: 7
    Last Post: 12-11-2012, 06:20 AM

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