+ Reply to Thread
Results 1 to 8 of 8

Need help to move duplicates from a list and paste them in a specific area on worksheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-28-2013
    Location
    Miami, United States
    MS-Off Ver
    Excel 365 (Newest version)
    Posts
    259

    Need help to move duplicates from a list and paste them in a specific area on worksheet

    Can anyone help me with a macro that can move the duplicates with unique shifts to the overtime bucket created in the same worksheet? is this possible?. if it is that will be a big help.

    I've attached the sample showing the end result.


    I would love for the macro to only move the duplicates with unique shifts to the area below highlighted.

    I pray to god that this is possible. I will sweat less.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Need help to move duplicates from a list and paste them in a specific area on workshee

    Hi Shellybelly
    You have the main list (lines 9-85) & then a gap of 9 lines until the duplicate list (lines 95-111). Is that gap of 9 always going to be there? If it's normally continuous lines of data, how do you determine who did the overtime? Is it because the name appears twice on the same day & the duplicate name is always the overtime entry? Richardo Joseph & Peta Alexander appear in the overtime bucket & the duplicate list, but aren't in the main list.
    Cheers
    Phil

  3. #3
    Forum Contributor
    Join Date
    04-28-2013
    Location
    Miami, United States
    MS-Off Ver
    Excel 365 (Newest version)
    Posts
    259

    Re: Need help to move duplicates from a list and paste them in a specific area on workshee

    Hi Philb1

    yep, the gap will always be there when i sort the shifts. The duplicate names are always the overtime entry.peta and richardo didn't duplicate but they have a unique shift from all the others above. so the overtime bucket will have the duplicate names and also persons with unique shifts as well.

  4. #4
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Need help to move duplicates from a list and paste them in a specific area on workshee

    Hi Shelly
    Try this. It looks for the word IN in column G in the duplicates range of cells & if it finds it, copies the name, the schedule, start & end times, & the OT breaks into the overtime bucket. The formulas in columns N & O are still intact.
    Let me know how it goes
    Cheers
    Phil

    Option Explicit
    
    Sub Overtimers()
    
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With
    
    Dim Ws4 As Worksheet
    Dim DupRange As Range ' Range of duplicates
    Dim rCell As Range ' Looping cell
    Dim i As Long ' Counter
    Dim strIN As String ' The word "IN"
    i = 117
    strIN = "IN"
    Set Ws4 = ThisWorkbook.Sheets(1)
    
    '   The range where Overtime workers appear
    Set DupRange = Ws4.Range(Ws4.Cells(95, 10), Ws4.Cells(114, 10))
    
    '   Delete contents from Overtime Bucket
    Ws4.Range(Ws4.Cells(117, 10), Ws4.Cells(131, 11)).ClearContents
    Ws4.Range(Ws4.Cells(117, 16), Ws4.Cells(131, 19)).ClearContents
    
    '   Loop through overtime worker range
        For Each rCell In DupRange
    '   If the adjacent cell in col G has the value IN, overtime has been committed
            If UCase(rCell.Offset(, -3).Value) = strIN Then
                With Ws4.Cells(i, 10) ' Top Cell Of Overtime Bucket
                    .Value = rCell.Value ' Name
                    .Offset(, 1).Value = rCell.Offset(, 1).Value ' Schedule
                    .Offset(, 6).Value = rCell.Offset(, 2).Value ' Start Time
                    .Offset(, 7).Value = rCell.Offset(, 3).Value ' End Time
                    .Offset(, 8).Value = rCell.Offset(, 8).Value ' OT Break
                    .Offset(, 9).Value = rCell.Offset(, 9).Value ' OT Lunch
                End With
                i = i + 1 ' Counter Up 1
            End If
        Next rCell
    
        With Application
            .DisplayAlerts = True
            .EnableEvents = True
            .Calculation = xlCalculationAutomatic
            .ScreenUpdating = True
        End With
    
    Exit Sub
    
    End Sub
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    04-28-2013
    Location
    Miami, United States
    MS-Off Ver
    Excel 365 (Newest version)
    Posts
    259

    Re: Need help to move duplicates from a list and paste them in a specific area on workshee

    Thank you sooo much Philb1. this is AWESOMEEEE!!!! however is it possible that the program name can be copied together with the duplicates also? if I could add multiple reputation points I would've.

  6. #6
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Need help to move duplicates from a list and paste them in a specific area on workshee

    This should do the trick. All the colour shaded areas of the overtime bucket are deleted & repopulated with the data from the overtime list each time the macro is run. I haven't included the total hours or the paid hours columns.
    Thanks for the rep

    Option Explicit
    
    Sub Overtimers()
    
    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With
    
    Dim Ws4 As Worksheet
    Dim DupRange As Range ' Range of duplicates
    Dim rCell As Range ' Looping cell
    Dim i As Long ' Counter
    Dim strIN As String ' The word "IN"
    i = 117
    strIN = "IN"
    Set Ws4 = ThisWorkbook.Sheets(1)
    
    '   The range where Overtime workers appear
    Set DupRange = Ws4.Range(Ws4.Cells(95, 10), Ws4.Cells(114, 10))
    
    '   Delete contents from Overtime Bucket
    With Ws4
        .Range(Ws4.Cells(117, 8), Ws4.Cells(131, 8)).ClearContents
        .Range(Ws4.Cells(117, 10), Ws4.Cells(131, 12)).ClearContents
        .Range(Ws4.Cells(117, 16), Ws4.Cells(131, 19)).ClearContents
    End With
    
    '   Loop through overtime worker range
        For Each rCell In DupRange
    '   If the adjacent cell in col G has the value IN, overtime has been committed
            If UCase(rCell.Offset(, -3).Value) = strIN Then
                With Ws4.Cells(i, 10) ' Top Cell Of Overtime Bucket
                    .Value = rCell.Value ' Name
                    .Offset(, -2).Value = rCell.Offset(, -2).Value ' Program
                    .Offset(, 1).Value = rCell.Offset(, 1).Value ' Schedule
                    .Offset(, 6).Value = rCell.Offset(, 2).Value ' Start Time
                    .Offset(, 7).Value = rCell.Offset(, 3).Value ' End Time
                    .Offset(, 8).Value = rCell.Offset(, 8).Value ' OT Break
                    .Offset(, 9).Value = rCell.Offset(, 9).Value ' OT Lunch
                End With
                i = i + 1 ' Counter Up 1
            End If
        Next rCell
    
        With Application
            .DisplayAlerts = True
            .EnableEvents = True
            .Calculation = xlCalculationAutomatic
            .ScreenUpdating = True
        End With
    
    Exit Sub
    
    End Sub
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    04-28-2013
    Location
    Miami, United States
    MS-Off Ver
    Excel 365 (Newest version)
    Posts
    259

    Re: Need help to move duplicates from a list and paste them in a specific area on workshee

    Thanks again Philb1 you were really great. You helped me big time. Thanks a million. It works like a charm!!

  8. #8
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Need help to move duplicates from a list and paste them in a specific area on workshee

    No problem

+ 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. Replies: 3
    Last Post: 02-23-2015, 06:51 AM
  2. Move duplicates to a new worksheet
    By Austinkitten in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-30-2013, 01:51 PM
  3. Macro/VBA to move specific data from one column to another (without duplicates)
    By JezVanderBrown in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2013, 06:36 AM
  4. Validation List to copy and paste in specific area (excel 2007)
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-24-2012, 02:22 PM
  5. Replies: 5
    Last Post: 05-01-2012, 04:02 PM

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