help to correct error  code duplicate data
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: help to correct error code duplicate data

  1. #1
    New Member
    Join Date
    May 2019
    Posts
    46
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default help to correct error code duplicate data

    hi, gays
    i have data in sheet1 i would transfer data just non duplicated to sheet 2 i try with this code but show me error " object required"
    and this is my code

    Code:
    Public Sub SumDuplicateData()
    
    
    Dim Srch As Range
    Sheet2.Range("A2:G100").Value = Empty
    
    For I = 2 To Sheet1.Range("F100").End(xlUp).Row
    Set Srch = Sheet2.Range("F2:F100").Find(Sheet1.Range("F" & I).Value)
    If Srch Is Nothing Then
    For j = 1 To 6
    Sheet2.Range(Cells(Sheet2.Range("F100").End(xlUp).Offset(1, 0).Row, j).Address).Value = Sheet1.Range(Cells(I, j).Address).Value
    Next j
    Sheet2.Range("G" & Sheet2.Range("F100").End(xlUp).Row).Value = Sheet2.Range("F100").End(xlUp).Row - 1
    Else
    For j = 1 To 3
    Sheet2.Range(Cells(Srch.Row, j).Address).Value = Sheet1.Range(Cells(I, j).Address).Value + Sheet2.Range(Cells(Srch.Row, j).Address).Value
    Next j
    End If
    Next I
    
    
    End Sub
    Last edited by mole999; Jul 22nd, 2019 at 02:47 AM. Reason: code tags as per forum rules

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,674
    Post Thanks / Like
    Mentioned
    64 Post(s)
    Tagged
    14 Thread(s)

    Default Re: help to correct error code duplicate data

    I do not understand what you have in your code, you can explain what you need.
    Regards Dante Amor

  3. #3
    Board Regular
    Join Date
    Jan 2018
    Posts
    202
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: help to correct error code duplicate data

    Quote Originally Posted by abdelfattah View Post
    i have data in sheet1 i would transfer data just non duplicated to sheet 2 i try with this code but show me error " object required"
    and this is my code
    The following macro is untested. Please read the comments I'm not entirely sure that I understood what your code is supposed to do
    Code:
    Public Sub SumDuplicateData()
    
        Dim Srch As Range, T As Long
    
        Sheet2.Range("A2:G100").clear 'clear this range
    
        T = Range("F100").End(xlUp).row 'last used row in Column F starting at row 100 going upwards
    
        For I = 2 To T
    
    Set Srch = Sheet2.Range("F2:F100").Find(Sheet1.Range("F" & I).Value2)
    
            If Srch Is Nothing Then 'If the sought range is not found
    
                For j = 1 To 6
    
                    Sheet2.Cells(T + 1, j).Value2 = Sheet1.Cells(I, j).Value2
                    'T + 1 Is last used row in Column F starting at row 100 going upwards then down 1
                Next j
    
                Sheet2.Range("G" & T).Value2 = Sheet2.Range("F" & T - 1).value2
    
                'T - 1 Is last used row in Column F starting at row 100 going upwards then up 1
                'Did you want a row number here or a value[currently set to value]?
                'If a row number is desired then change Sheet2.Range("F" & T - 1).value2 to Sheet2.Range("F" & T - 1).row
    
            Else
    
                For j = 1 To 3
    
                    Sheet2.Cells(Srch.Row, j).Value2 = Sheet1.Cells(I, j).Value2 + Sheet2.Cells(Srch.Row, j).Value2
    
                Next j
    
            End If
    
        Next I
    
    End Sub
    Last edited by MoshiM; Jul 21st, 2019 at 09:13 PM. Reason: clarity

  4. #4
    Board Regular
    Join Date
    Jan 2018
    Posts
    202
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: help to correct error code duplicate data

    change .clear to .clearcontents

  5. #5
    New Member
    Join Date
    May 2019
    Posts
    46
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: help to correct error code duplicate data

    i would find the mistake about error message what i mentioned
    i have sheet1 contains data some of them duplicated i wanna transfer total values duplicated data to sheet2
    when i run the macro ocurres error this message object requires
    i hope this clear

  6. #6
    Board Regular
    Join Date
    Jan 2018
    Posts
    202
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Default Re: help to correct error code duplicate data

    Quote Originally Posted by abdelfattah View Post
    i would find the mistake about error message what i mentioned
    i have sheet1 contains data some of them duplicated i wanna transfer total values duplicated data to sheet2
    when i run the macro ocurres error this message object requires
    i hope this clear
    Where are you getting the error?

    Also change
    Code:
    T = Range("F100").End(xlUp).row
    to
    Code:
    T = Sheet2.Range("F100").End(xlUp).row

  7. #7
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,674
    Post Thanks / Like
    Mentioned
    64 Post(s)
    Tagged
    14 Thread(s)

    Default Re: help to correct error code duplicate data

    Quote Originally Posted by abdelfattah View Post
    i would find the mistake about error message what i mentioned
    i have sheet1 contains data some of them duplicated i wanna transfer total values duplicated data to sheet2
    when i run the macro ocurres error this message object requires
    i hope this clear
    Forget the code a bit, explain how your data is and what you need to do.
    I understand that you want to copy lake from one part to another part.
    But I do not know how your data is, nor what do you mean by "some of them duplicated and wanna transfer total values ​​duplicated"

    Just write some examples.
    If there are duplicates, in which column or which columns.
    If there are 5 duplicates, do you want to copy or move the 5 records or only 4, which 4? the first, the last?
    Regards Dante Amor

  8. #8
    New Member
    Join Date
    May 2019
    Posts
    46
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: help to correct error code duplicate data

    Quote Originally Posted by DanteAmor View Post
    Forget the code a bit, explain how your data is and what you need to do.
    I understand that you want to copy lake from one part to another part.
    But I do not know how your data is, nor what do you mean by "some of them duplicated and wanna transfer total values ​​duplicated"

    Just write some examples.
    If there are duplicates, in which column or which columns.
    If there are 5 duplicates, do you want to copy or move the 5 records or only 4, which 4? the first, the last?
    let me more explanation
    i have sheet1 containes data in cells from a2: g100 ok when i fill data i have duplicated data i would transfer the data to sheet2
    SHEET1:
    a b c d e f g
    ITEM BRAND TYPE ORIGIN IMPORT EXPORT BALANCE
    1 1200R20 G580 THI 200 50 150
    2 1200R20 G580 THI 300 150 150

    AND WHAT IWOUL SHOW THE RESULT IN SHEET2 LIKE THIS
    a b c d e f g
    ITEM BRAND TYPE ORIGIN IMPORT EXPORT BALANCE
    1 1200R20 G580 THI 500 200 300
    i hope this clear

  9. #9
    New Member
    Join Date
    May 2019
    Posts
    46
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: help to correct error code duplicate data

    thank's MoshiM but, it doesn't work you're change when i run the macro show this error "object required"
    Last edited by abdelfattah; Jul 22nd, 2019 at 11:49 AM.

  10. #10
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    5,674
    Post Thanks / Like
    Mentioned
    64 Post(s)
    Tagged
    14 Thread(s)

    Default Re: help to correct error code duplicate data

    Quote Originally Posted by abdelfattah View Post
    let me more explanation
    i have sheet1 containes data in cells from a2: g100 ok when i fill data i have duplicated data i would transfer the data to sheet2
    SHEET1:
    a b c d e f g
    ITEM BRAND TYPE ORIGIN IMPORT EXPORT BALANCE
    1 1200R20 G580 THI 200 50 150
    2 1200R20 G580 THI 300 150 150

    AND WHAT IWOUL SHOW THE RESULT IN SHEET2 LIKE THIS
    a b c d e f g
    ITEM BRAND TYPE ORIGIN IMPORT EXPORT BALANCE
    1 1200R20 G580 THI 500 200 300
    i hope this clear
    You could get that result with a pivot table:



    But if the macro is necessary...
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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