Consulting

Results 1 to 5 of 5

Thread: Double Entries

  1. #1

    Double Entries

    Afternoon

    I am having a problem with one of my macro's. I have a excel main sheet and all the months on a different sheets in the same document. On the main sheet i have a end date and the macro takes the end date and copies that line to the correct month. Now if i go into the document tomorrow and add loads more line in the master documents and then press go it re-sorts and copies all the line even the old ones into the months making double entries. Is there a way to for it to check or stop making the double entries and only add the new lines.

    Here is the code i have for sorting it:
    Option Explicit
    Const CountColumn = 15 ' the column in which the count formula is to be entered
    
    
    
    
    
    Private Sub Go_Click()
    
    Dim currentMonth As Variant, intLimit As Variant, intX As Variant, intCurrentRow As Integer
    Dim months
    months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
    ThisWorkbook.Sheets("January").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("February").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("March").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("April").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("May").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("June").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("July").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("August").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("September").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("October").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("November").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("December").Cells(1, CountColumn) = "=count(A:A)+1"
    ThisWorkbook.Sheets("Master").Cells(1, CountColumn) = "=count(A:A)+1"
    
    
    
    Dim tmpSheetName As String
    intLimit = Int(ThisWorkbook.Sheets("Master").Cells(1, CountColumn).Value)
    
    For intX = 2 To intLimit
        currentMonth = Int(ThisWorkbook.Sheets("Master").Cells(intX, 14).Value) - 1
        tmpSheetName = months(currentMonth)
        Sheets("Master").Select
        ActiveSheet.Range("A" & intX & ":M" & intX).Select
        Selection.Copy
        Sheets(tmpSheetName).Select
        intCurrentRow = Int(ThisWorkbook.Sheets(tmpSheetName).Cells(1, CountColumn).Value) + 1
        ActiveSheet.Range("A" & intCurrentRow).Select
        Selection.PasteSpecial (xlPasteAll)
    Next intX
    
    End Sub
    Help would be appreciated.
    Thanks

  2. #2
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    Spike,

    Question. Does any one day's import contain mixed transaction dates or do all those transactions have the same transaction date? Why do you sort the table before copying to the month worksheets?

    Suggestion: add a column to your table for a boolean "Posted? (Y/N=blank)." You can sort on this and the date (in that order) to isolate the lines needing to be copied and allowing you to copy all of those for each month as a block for a little efficiency. After copying and pasting, update the Posted flag and re-sort the transactions by date.

    Can you post a sample file with any incriminating ('er proprietary) information obfuscated? That would help us help you.

    Cheers,
    Ron
    Windermere, FL

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post a workbook containing sample date?. Use Manage Attachments in the Go Advanced section.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Cheers
    Andy

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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