+ Reply to Thread
Results 1 to 3 of 3

Duplication data every time macro is run, instead of updating newly found data only

Hybrid View

Lostinxcel Duplication data every time... 03-09-2010, 10:36 AM
jaslake Re: Duplication data every... 03-09-2010, 12:31 PM
Lostinxcel Re: Duplication data every... 03-10-2010, 03:41 AM
  1. #1
    Registered User
    Join Date
    02-25-2010
    Location
    Malta
    MS-Off Ver
    Excel 2007
    Posts
    7

    Duplication data every time macro is run, instead of updating newly found data only

    Hi,

    I had posted my problem before and thought it was solved after receiving great help.

    (http://www.excelforum.com/excel-prog...ml#post2266996)

    However, I just found out that there is a slight problem with the code I had received (for my purpose). It keeps duplicating the data every time the macro is run, while I need it to just update the new data, found in the worksheet I work on daily, in the specified new worksheet.

    Any help on solving this would be very much appreciated. Cheers.

    Here's the code and I have also included the sample excel file:

    Sub UpdateInvoiceSheet()
        Dim ws1 As Worksheet: Dim ws2 As Worksheet
        Dim rRpt As Range
        
        Set ws1 = Worksheets("Receipts PYMT 2010")
        Set ws2 = Worksheets("Invoice Cost Overview 2010")
        
        y = ws2.UsedRange.Rows.Count + 1
        For Each rRpt In ws1.Range("E2:E" & ws1.UsedRange.Rows.Count)
            If rRpt = 0.7 Or rRpt = 1 Then
                ws2.Cells(y, "B") = ws1.Cells(rRpt.Row, "I")
                ws2.Cells(y, "C") = ws1.Cells(rRpt.Row, "A")
                ws2.Cells(y, "D") = ws1.Cells(rRpt.Row, "G")
                y = y + 1
            End If
        Next rRpt
    End Sub
    Attached Files Attached Files
    Last edited by Lostinxcel; 03-10-2010 at 03:43 AM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Duplication data every time macro is run, instead of updating newly found data on

    Hi Lostinxcel

    Try this
    Sub UpdateInvoiceSheet()
        Dim ws1 As Worksheet: Dim ws2 As Worksheet
        Dim rRpt As Range
    
        Set ws1 = Worksheets("Receipts PYMT 2010")
        Set ws2 = Worksheets("Invoice Cost Overview 2010")
    
        y = ws2.UsedRange.Rows.Count + 1
        For Each rRpt In ws1.Range("E2:E" & ws1.UsedRange.Rows.Count)
            If rRpt = 0.7 Or rRpt = 1 Then
                If Not rRpt.Offset(0, 8).Value = "x" Then 'put this marker column anywhere you want
                    ws2.Cells(y, "B") = ws1.Cells(rRpt.Row, "I")
                    ws2.Cells(y, "C") = ws1.Cells(rRpt.Row, "A")
                    ws2.Cells(y, "D") = ws1.Cells(rRpt.Row, "G")
                    y = y + 1
                    rRpt.Offset(0, 8).Value = "x" 'after you've used the item, mark it so it's not duplicated
                End If
            End If
        Next rRpt
    End Sub
    The code places a marker in Receipts PYMT 2010 when an Item is used so it doesn't get used again.

    Hope this helps.

    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    02-25-2010
    Location
    Malta
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Duplication data every time macro is run, instead of updating newly found data on

    Thank you very much John, highly appreciated.

    That solved my problem.

    Cheers,

    Erik

+ 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