+ Reply to Thread
Results 1 to 10 of 10

Create Entries on another sheet based on frequencies

Hybrid View

  1. #1
    Registered User
    Join Date
    03-18-2010
    Location
    Layton, UT
    MS-Off Ver
    Excel 2013
    Posts
    73

    Create Entries on another sheet based on frequencies

    I need help in making this workbook create transactions for the year based on the Frequencies listed. For example, because Bank of America Dividend Income is due/paid Weekly, it should appear 52 times starting with the First Due Date, and every week after (Jan 9, Jan 16, Jan 23, Jan 30, Feb 6, and so on). Based on current setting in grid at left, (see Expected Results sheet) this is what I need help in getting to show up on the "Budget Entries" sheet, columns in the order shown (Original Sequence column info only). If all 8 rows had frequency of Weekly, there would be (8x 52=) 416 entries on on the Budget Entries sheet, so code or formulas need to be flexible to accommodate change number of entries.
    Thanks very much for any help.
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Create Entries on another sheet based on frequencies

    Woo... that was not as small a task as I first envisioned. There is some hidden traps here with each data type, so hopefully this gives you what you want AND takes care of those off years where December has more pay weeks than normal, Weekly and Bi-Weekly specifically at issue.

    Option Explicit
    
    Sub AddYearlyEntries()
    Dim Dates As Range, MyDate As Range, NR As Long, rws As Long, DateRw As Long, ChkDate As Range
    
    Set Dates = Sheets("Budget Input UI").Range("F:F").SpecialCells(xlConstants, xlNumbers)
    With Sheets("Budget Entries")
        For Each MyDate In Dates
            NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1
            Select Case LCase(MyDate.Offset(, -1))
                Case "weekly":          rws = 52
                Case "bi-weekly":       rws = 26
                Case "semi-monthly":    rws = 24
                Case "monthly":         rws = 12
                Case "bi-monthly":      rws = 6
                Case "quarterly":       rws = 4
                Case "semi-annually":   rws = 2
                Case "annually":        rws = 1
            End Select
            .Range("A" & NR & ":C" & NR).Resize(rws).Value = MyDate.Offset(, -5).Resize(, 3).Value
            .Range("D" & NR).Value = MyDate.Value
            .Range("E" & NR).Resize(rws).Value = MyDate.Offset(, -2).Value
            .Range("F" & NR).Resize(rws).Value = MyDate.Offset(, 1).Value
            For DateRw = NR + 1 To NR + rws - 1
                Set ChkDate = .Range("D" & DateRw - 1)
                Select Case LCase(MyDate.Offset(, -1))
                    Case "weekly"
                        .Range("D" & DateRw).Value = ChkDate.Value + 7
                        If .Range("A" & DateRw + 1) = "" Then
                            If Day(.Range("D" & DateRw).Value) = 24 Then
                                .Range("A" & DateRw).EntireRow.Copy .Range("A" & DateRw + 1)
                                .Range("D" & DateRw + 1).Value = ChkDate + 14
                            End If
                        End If
                    Case "bi-weekly"
                        .Range("D" & DateRw).Value = ChkDate.Value + 14
                        If .Range("A" & DateRw + 1) = "" Then
                            If Day(ChkDate.Value) <= 3 Then
                                .Range("A" & DateRw).EntireRow.Copy .Range("A" & DateRw + 1)
                                .Range("D" & DateRw + 1).Value = ChkDate + 28
                            End If
                        End If
                    Case "semi-monthly"
                        Select Case Day(ChkDate)
                            Case 1 To 14
                                .Range("D" & DateRw).Value = ChkDate.Value + 14
                            Case Else
                                .Range("D" & DateRw).Value = DateSerial(Year(ChkDate.Offset(-1)), Month(ChkDate.Offset(-1)) + 1, Day(ChkDate.Offset(-1)))
                        End Select
                    Case "monthly"
                        .Range("D" & DateRw).Value = DateSerial(Year(ChkDate), Month(ChkDate) + 1, Day(ChkDate))
                    Case "bi-monthly"
                        .Range("D" & DateRw).Value = DateSerial(Year(ChkDate), Month(ChkDate) + 2, Day(ChkDate))
                    Case "quarterly"
                        .Range("D" & DateRw).Value = DateSerial(Year(ChkDate), Month(ChkDate) + 3, Day(ChkDate))
                    Case "semi-annually"
                        .Range("D" & DateRw).Value = DateSerial(Year(ChkDate), Month(ChkDate) + 6, Day(ChkDate))
                    Case "annually"
                        'do nothing
                End Select
            Next DateRw
        Next MyDate
        .Range("D:D").NumberFormat = "mm/dd/yy"
        .Range("F:F").Style = "Currency"
        .Range("A:F").Sort .Range("D2"), xlAscending, .Range("E2"), , xlAscending, Header:=xlYes
        .Columns.AutoFit
    End With
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-18-2010
    Location
    Layton, UT
    MS-Off Ver
    Excel 2013
    Posts
    73

    Re: Create Entries on another sheet based on frequencies

    Thanks you so much for your help. I inserted a module in my workbook and pasted your code inside, then created a command button and assigned to it the code. However, I get a 'script out of range' error when I click the button.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Create Entries on another sheet based on frequencies

    Hi Catnam,

    Try this:

    Sub Catnam(): Dim Typ As String, Cat As String, Sct As String, Pyr As String
    Dim FDD As Date, Amt As Single, p As Long, q As Long, r As Long, er As Long
    Dim wi As Worksheet, we As Worksheet, F, T, i As Integer, n As Integer
    
    F = Array(" ", "weekly", "bi-weekly", "bi-monthly", "semi-monthly", _
                        "monthly", "quarterly", "semi-annually", "annually")
    T = Array(0, 52, 26, 24, 12, 6, 4, 2, 1)
    
    Set we = ActiveWorkbook.Sheets("Budget Entries")
    we.Range("F:F").NumberFormat = "0.00"
    Set wi = ActiveWorkbook.Sheets("Budget Input UI ") 'a space after UI here
    er = 4: Do Until wi.Cells(er + 1, 1) = "": er = er + 1: Loop: q = 1
    
    LoadIns:
    
    For r = 4 To er
    Typ = wi.Cells(r, 1): Cat = wi.Cells(r, 2): Sct = wi.Cells(r, 3)
    Pyr = wi.Cells(r, 4): FDD = wi.Cells(r, 6): Amt = wi.Cells(r, 7)
    
    For i = 1 To UBound(F)
    If LCase(wi.Cells(r, 5)) = F(i) Then
    n = Int(365 / T(i) + 0.5): Exit For: End If
    Next i: p = T(i) - 1
    
    For i = 0 To p: q = q + 1
    we.Cells(q, 1) = Typ: we.Cells(q, 2) = Cat: we.Cells(q, 3) = Sct
    we.Cells(q, 4) = FDD + i * n: we.Cells(q, 5) = Pyr: we.Cells(q, 6) = Amt
    Next i
    Next r
    
    we.Cells.sort Key1:=Range("D1"), Order1:=xlAscending, Header:=xlYes
    
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Registered User
    Join Date
    03-18-2010
    Location
    Layton, UT
    MS-Off Ver
    Excel 2013
    Posts
    73

    Re: Create Entries on another sheet based on frequencies

    Thanks so much, it worked just fine. Also thanks for adding the dollar signs. Sweet!!!

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Create Entries on another sheet based on frequencies

    Yes, I had that problem, too. Your sheet name has a hidden space at the end, take that out.

    "Budget Input UI "

  7. #7
    Registered User
    Join Date
    03-18-2010
    Location
    Layton, UT
    MS-Off Ver
    Excel 2013
    Posts
    73

    Re: Create Entries on another sheet based on frequencies

    Thanks. I fixed that, now it works great.

  8. #8
    Registered User
    Join Date
    03-18-2010
    Location
    Layton, UT
    MS-Off Ver
    Excel 2013
    Posts
    73

    Re: Create Entries on another sheet based on frequencies

    The code works great! Thanks so so much. I have just one little issue. While all the data post just the way I want, I get a Run-time error "1004': "The sort reference is not valid. Make sure that it's within the data you want to sort, and the first Sort by Box isn't the same or blank. What do that mean?

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Create Entries on another sheet based on frequencies

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  10. #10
    Registered User
    Join Date
    03-18-2010
    Location
    Layton, UT
    MS-Off Ver
    Excel 2013
    Posts
    73

    Re: Create Entries on another sheet based on frequencies

    Got it done. Thanks again.

+ 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. Replies: 7
    Last Post: 07-27-2013, 10:11 PM
  2. Create entries based on date
    By udayg10 in forum Excel General
    Replies: 5
    Last Post: 03-07-2013, 08:58 AM
  3. [SOLVED] Populating a cell based on one of two entries on a different sheet
    By mikerules in forum Excel General
    Replies: 2
    Last Post: 08-09-2012, 02:49 AM
  4. Copies entries on master sheet to specific tabs based on 2 criteria
    By kate8301 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-16-2011, 03:48 PM
  5. Create an outcome based on two Cell Entries
    By quasifun in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 11-27-2007, 10:30 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