+ Reply to Thread
Results 1 to 3 of 3

Ensure running a macro doesn't produce duplicate data

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Seattlle, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Exclamation Ensure running a macro doesn't produce duplicate data

    Hi,
    I have added code to copy certain cells from a worksheet (Invoice Tracker) to a new worksheet (Houston-P) if a value in column B is equal to "HH". This is working but everything I run the macro, it copies cells it has copied before so my new worksheet contains a bunch of duplicates. How can I add to this code below so that it doesnt do that?
    Thank you!

    Sub Exporting_Data1()
    Dim i As Long, LR As Long, X As Long, a, ms As Worksheet
    Application.ScreenUpdating = False
    Set ms = Worksheets("Houston-P")
    On Error Resume Next

    With Worksheets("Invoice Tracker")
    LR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
    For i = 1 To LR
    If .Cells(i, "B") = "HH" Then
    a = Array(.Cells(i, "A").Value, .Cells(i, "B").Value, .Cells(i, "D").Value, .Cells(i, "F").Value, .Cells(i, "G").Value, .Cells(i, "H").Value, .Cells(i, "O").Value, .Cells(i, "P").Value)
    ms.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Resize(, 8) = a
    End If
    Next i

    End With
    Application.CutCopyMode = 0
    Application.ScreenUpdating = True
    Set ms = Nothing
    End Sub
    Last edited by mhenry123; 04-14-2013 at 09:34 PM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Ensure running a macro doesn't produce duplicate data

    Hi, mhenry123,

    use either WorksheetFunction.CountIf on your invoice number and only copy if the result is 0 or VLookup not returning #N/A. Assuming that the invoice number is in Column A, code is untested:
    Please Login or Register  to view this content.
    Please amend Code-Tags around the procedure in your post.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    03-27-2013
    Location
    Seattlle, USA
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Ensure running a macro doesn't produce duplicate data

    Thanks so much Holger! It worked!!

+ 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