VBA Code remove duplicates not working

Kra

Board Regular
Joined
Jul 4, 2022
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Code works fine till 'Remove duplicates. It does nothing after pasting data. Does anybody know how to fix 'Remove duplicates and 'Drag down formulas?


VBA Code:
Sub PricingTransferZVOL()
     
'Delete old data in LSMW ZVOL MATERIAL sheet
    Worksheets("LSMW ZVOL MATERIAL").Rows(7 & ":" & Worksheets("LSMW ZVOL MATERIAL").Rows.Count).Delete
     
'Set filters to ZVOL
    Call Removefilters
    Call ZVOLFilter
    
    Dim answer As Integer
    Dim LastRowZVOL As Integer
    Dim UsdRw As Integer
    Dim LastRow As Integer
    
    LastRow = Worksheets("SUM").Cells(Rows.Count, 1).End(xlUp).Row
    LastRowZVOL = Worksheets("LSMW ZVOL MATERIAL").range("B" & Rows.Count).End(xlUp).Row
    UsdRw = Worksheets("LSMW ZVOL MATERIAL").range("B" & Rows.Count).End(xlUp).Row
    

    On Error GoTo Done
'Pop-up: Continue with macro?
        answer = MsgBox("Continue?", vbQuestion + vbYesNo + vbDefaultButton2, "ZVOL Material")
        
        If answer = vbYes Then
        
'Copy and paste data
            Worksheets("SUM").range("AT3:AW" & LastRow).Select
            Selection.Copy Worksheets("LSMW ZVOL MATERIAL").range("A4")
            Worksheets("LSMW ZVOL MATERIAL").range("A4:D" & LastRowZVOL).RemoveDuplicates Columns:=Array(1, 2, 3, 4)
    
     Application.CutCopyMode = False
    
'Remove duplicates
       
    Worksheets("LSMW ZVOL MATERIAL").range("A4:D" & LastRowZVOL).RemoveDuplicates Columns:=Array(1, 2, 3, 4)
    
'Drag down formulas
        
    
     Worksheets("LSMW ZVOL MATERIAL").range("E5:AA5").AutoFill _
        Destination:=Worksheets("LSMW ZVOL MATERIAL").range("E5:AA" & UsdRw), _
        Type:=xlFillCopy
        
    End If
        
    
Done:
    
    On Error GoTo 0
    
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I tried to change it and tidy it up, but it still doesn't work.


VBA Code:
Public Function GetLastRow(Optional Col As Integer = 1, Optional Sheet As Excel.Worksheet)

    If Sheet Is Nothing Then
        Set Sheet = Worksheets("LSMW ZVOL MATERIAL")
    End If
    GetLastRow = Sheet.Cells(Sheet.Rows.Count, Col).End(xlUp).Row
 End Function





Sub PricingTransferZPR0()

    Dim LastRow As Integer
    
    LastRow = Worksheets("SUM").Cells(Rows.Count, 1).End(xlUp).Row
    
'Set filters to ZPR0
    Call Removefilters
    Call ZPR0Filter
    
'Delete old data in LSMW ZPR0 sheet
    Worksheets("LSMW ZPR0").Rows(2 & ":" & Worksheets("LSMW ZPR0").Rows.Count).Delete
 
'Copy and paste data
    range("V3:AS" & LastRow).Select
    Selection.Copy Worksheets("LSMW ZPR0").range("A2")
 
     Application.CutCopyMode = False
     
End Sub

Sub PricingTransferZVOL()

    Dim LastRow As Integer

        LastRow = GetLastRow(1, Worksheets("SUM"))
    
    Dim LastRowZVOL As Integer
    
        LastRowZVOL = GetLastRow(1, Worksheets("LSMW ZVOL MATERIAL"))
     
    Dim UsdRw As Integer
    
        UsdRw = GetLastRow(1, Worksheets("LSMW ZVOL MATERIAL"))
        
     
'Delete old data in LSMW ZVOL MATERIAL sheet
    Worksheets("LSMW ZVOL MATERIAL").Rows(7 & ":" & Worksheets("LSMW ZVOL MATERIAL").Rows.Count).Delete
    Worksheets("LSMW ZVOL MATERIAL").range("A4:D6").ClearContents
    
    
'Set filters to ZVOL
    Call Removefilters
    Call ZVOLFilter
    
'Select and copy
    range("AT3:AW" & LastRow).Select
    Selection.Copy Worksheets("LSMW ZVOL MATERIAL").range("A4")
    
'Remove duplicates

    Worksheets("LSMW ZVOL MATERIAL").range("A4:D" & LastRowZVOL).RemoveDuplicates Columns:=Array(1, 2, 3, 4)
    
 'Drag down formulas
 
    Worksheets("LSMW ZVOL MATERIAL").range("E5:AA5").AutoFill _
        Destination:=Worksheets("LSMW ZVOL MATERIAL").range("E5:AA" & UsdRw), _
        Type:=xlFillCopy
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top