+ Reply to Thread
Results 1 to 3 of 3

need help on easy VBA quickly

Hybrid View

  1. #1
    Registered User
    Join Date
    03-07-2005
    Posts
    15

    need help on easy VBA quickly

    I have a couple of things that i need to automate in Excel using VBA.
    1) I input a beginning date for a policy and an ending date. Based on the two dates, first i want the macro to put the number of months onto a cell on that sheet.
    2) then depending on the number of months, i want it to populate that many rows with 1,2,3.....n (the number) going down on a column which may say (number of months).
    3) as long as the month is less than equal to 12 the column next to it displays 1 (the year column). as soon as the number in the months is greater than 12, the year becomes 2 all the way to 24th month and continuing so on.
    So in essence if the policy was active for 5 months, it populates that many rows, and if policy was active for 68 months, i want it to display 1-68 down and the corresponding year from 1-5
    Lastly,
    Based on the number of months say 15, i want a message box to say, please input the opening prices for this fund every month. so i take 15 inputs and put it in the next column and depending on that it gives me a admin charge on another column based on a ratio. After i've done the above, I'll ask how to get the ratio
    PLEASE DO HELP AS THIS IS NEEDED ASAP.

  2. #2
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    B1 has start date
    B2 has end date.

    Enter the following code in the module for your sheet

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "$B$2" Then

    Range("B3") = "=12*(YEAR(B2)-YEAR(B1))+MONTH(B2)-MONTH(B1)+1"

    Set startRange = Range("C10")

    startRange.Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.ClearContents


    For i = 1 To Range("B3").Value

    Range("C10").Offset(i - 1, 0) = i
    Range("C10").Offset(i - 1, 1) = Application.RoundUp(i / 12, 0)

    Next i

    End If

    Range("B2").Select

    End Sub


    This is not complete code. got to go. will continue tomorrow. The present code just puts the number of months and years in place.

    Just for you to get an idea...

    - Mangesh

  3. #3
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    Here's the complete solution:

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "$B$2" Then

    Range("B3") = "=12*(YEAR(B2)-YEAR(B1))+MONTH(B2)-MONTH(B1)+1"

    Set startRange = Range("C10")

    startRange.Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.ClearContents


    For i = 1 To Range("B3").Value

    Range("C10").Offset(i - 1, 0) = i
    Range("C10").Offset(i - 1, 1) = Application.RoundUp(i / 12, 0)

    Next i

    Range("B2").Select

    For j = 1 To Range("B3").Value

    Range("E" & 10).Offset(j - 1, 0) = InputBox("Enter value for month: " & j, "Opening Prices")

    Next j

    End If


    End Sub



    - Mangesh

+ Reply to 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