+ Reply to Thread
Results 1 to 11 of 11

Help Needed Moving data and rows from different sheets while updating prior data.

Hybrid View

  1. #1
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Help Needed Moving data and rows from different sheets while updating prior data.

    Quote Originally Posted by Raistlin8522 View Post
    What I am having trouble with now is that sometimes the script is causing the records to be duplicated several times. I am not sure why this is happening.
    Because the code is written based on the assumption that NO duplicate within a sheet.
    If duplicate within a sheet, take only the first data.
    If not, you need to show me your desired result with the duplicates.
    Sub test()
        Dim a, i As Long, ii As Long, w
        With Sheets("mastersheet").ListObjects("Table1")
            a = .DataBodyRange.Value
            .DataBodyRange.ClearContents
            ReDim w(1 To UBound(a, 2))
            With CreateObject("Scripting.Dictionary")
                For i = 1 To UBound(a, 1)
                    If a(i, 1) <> "" Then
                        If Not .exists(a(i, 1)) Then
                            For ii = 1 To UBound(a, 2)
                                w(ii) = a(i, ii)
                            Next
                            .Item(a(i, 1)) = w
                        End If
                    End If
                Next
                a = Sheets("DataSheet").Cells(1).CurrentRegion.Value
                For i = 2 To UBound(a, 1)
                    If a(i, 1) <> "" Then
                        If .exists(a(i, 1)) Then
                            w = .Item(a(i, 1))
                        Else
                            ReDim w(1 To UBound(w))
                        End If
                        For ii = 1 To UBound(a, 2)
                            w(ii) = a(i, ii)
                        Next
                        .Item(a(i, 1)) = w
                    End If
                Next
                a = Application.Index(.items, 0, 0)
            End With
            .DataBodyRange.Resize(UBound(a, 1)).Value = a
        End With
    End Sub

  2. #2
    Registered User
    Join Date
    02-13-2022
    Location
    USA
    MS-Off Ver
    Microsoft 365 Apps for Enterprise
    Posts
    15

    Re: Help Needed Moving data and rows from different sheets while updating prior data.

    Quote Originally Posted by jindon View Post
    Because the code is written based on the assumption that NO duplicate within a sheet.
    If duplicate within a sheet, take only the first data.
    If not, you need to show me your desired result with the duplicates.
    Sub test()
        Dim a, i As Long, ii As Long, w
        With Sheets("mastersheet").ListObjects("Table1")
            a = .DataBodyRange.Value
            .DataBodyRange.ClearContents
            ReDim w(1 To UBound(a, 2))
            With CreateObject("Scripting.Dictionary")
                For i = 1 To UBound(a, 1)
                    If a(i, 1) <> "" Then
                        If Not .exists(a(i, 1)) Then
                            For ii = 1 To UBound(a, 2)
                                w(ii) = a(i, ii)
                            Next
                            .Item(a(i, 1)) = w
                        End If
                    End If
                Next
                a = Sheets("DataSheet").Cells(1).CurrentRegion.Value
                For i = 2 To UBound(a, 1)
                    If a(i, 1) <> "" Then
                        If .exists(a(i, 1)) Then
                            w = .Item(a(i, 1))
                        Else
                            ReDim w(1 To UBound(w))
                        End If
                        For ii = 1 To UBound(a, 2)
                            w(ii) = a(i, ii)
                        Next
                        .Item(a(i, 1)) = w
                    End If
                Next
                a = Application.Index(.items, 0, 0)
            End With
            .DataBodyRange.Resize(UBound(a, 1)).Value = a
        End With
    End Sub
    I think the problem is with how I am moving your code to my actual file with sensitive information inside it. Everything seems to be the same but for some reason on the file that I move the code into it is creating a duplicate each time I run the VBA to test it. I am sure that it is me doing something incorrectly. I am not very good at VBA so I am not sure how to identify the area that I am having trouble with.

    Both files have [MasterSheet]
    Both files have [DataSheet]
    Both files refer to [Table1] on master sheet.
    The only thing I see that is different are slightly different Column Names, however the values are in the same order.

    Yet when I run the code in the workbook above it runs perfectly.
    When I place the code in the actual workbook it runs well the first time. Then if I change one value [aging days] it creates duplicates of almost every row below that point and of that record.

    I am thinking that I am missing something in the use of the code or that I am not applying it to my new workbook correctly. Do the column names matter and if so how would I change that? All Columns are in the same order {Case ID} > {Age}>{Description}> {Comments}.

    Steps I took:
    I confirmed there were no duplicate case ID's.
    Then I ran the macro to update the sheet.
    Confirmed no duplicates again ( there were none at this point)
    Changed the aging days on one record from 5 to 25
    Ran the Code again and now I have two records one is at 5 days aging and the other is at 25 days aging.

    Where am I messing this up at. Id love to show the actual data but cannot. And it seems to be working in the sample workbook. This to me means that I am the issue, sadly. It is my execution that is causing this to fail. Any additional help to get this transferred over to the book correctly would be amazing. But I cannot duplicate the issue in the supplied book either. Only in the book that I move the code to, that I cannot share.

    Thank- you for all the help. Hopefully this will help someone else as well.

+ 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. Updating certain cells while moving down a row of data
    By cytochrome in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-09-2017, 01:30 AM
  2. Moving rows of data to multiple sheets based on status for project pipeline
    By sthiessen85 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2015, 08:55 AM
  3. [SOLVED] Moving rows of data to multiple sheets based on status
    By sthiessen85 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-18-2015, 01:21 PM
  4. Replies: 4
    Last Post: 01-05-2015, 10:43 AM
  5. Replies: 0
    Last Post: 07-23-2013, 04:02 PM
  6. Automatically moving data rows to other sheets as new entires are added.
    By yehuoy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-21-2011, 05:11 PM
  7. [SOLVED] How do I group rows prior to a data sort so they stay together?
    By Linda Mills in forum Excel General
    Replies: 4
    Last Post: 08-17-2005, 04:05 PM

Tags for this Thread

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