VBA duplicates

3badi

New Member
Joined
Apr 23, 2019
Messages
5
Hi I am new in using VBA

I need help in this:

Sub duplicate3()
'
' duplicate3 Macro
'


'
Selection.CurrentRegion.Select
ActiveSheet.Range("$A$1:$G$356").RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, _
7), Header:=xlNo
End Sub

How can I make the range dynamic so it changes regardless of the data

Thank you
 

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
Hi & welcome to MrExcel

How about
Code:
Sub badi()
   Dim i As Long
   Dim Ary As Variant
   
   With Range("A1").CurrentRegion
      ReDim Ary(1 To .Columns.Count)
      For i = 1 To .Columns.Count
         Ary(i) = i
      Next i
      .RemoveDuplicates Ary, xlYes
   End With
End Sub
 
Upvote 0
The code is ready to run. It will delete any rows where the entire row is duplicated.
 
Upvote 0
Alright what about here how can I make it work in here I need it to remove the duplicates and fit with any range

Sub append_data()
'
' append_data Macro
'


'
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Selection.CurrentRegion.Select
Selection.Copy
Workbooks.Open Filename:= _
"C:\Users\abdullah.alzadjali\Documents\Oman VBA\VBA\Orders.xlsx"
Range("A1").Select
Selection.End(xlDown).Select
'range("A3267").Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.CurrentRegion.Select
Selection.CurrentRegion.Select
Selection.CurrentRegion.Select

ActiveWindow.Close savechanges:=True
Application.CutCopyMode = False
Range("A1").Select
End Sub

by the way I need the code to be put before the bold area

Thanks
 
Upvote 0
How about
Code:
Sub append_data()
'
' append_data Macro
'

   Dim i As Long
   Dim Ary As Variant
'
   Rows("1:1").Select
   Selection.Delete Shift:=xlUp
   Selection.CurrentRegion.Select
   Selection.Copy
   Workbooks.Open FileName:= _
   "C:\Users\abdullah.alzadjali\Documents\Oman VBA\VBA\Orders.xlsx"
   Range("A1").Select
   Selection.End(xlDown).Select
   'range("A3267").Select
   ActiveCell.Offset(1, 0).Range("A1").Select
   Selection.PasteSpecial paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
   :=False, Transpose:=False
   With Range("A1").CurrentRegion
      ReDim Ary(1 To .Columns.count)
      For i = 1 To .Columns.count
         Ary(i) = i
      Next i
      .RemoveDuplicates Ary, xlYes
   End With
   ActiveWindow.Close savechanges:=True
   Application.CutCopyMode = False
   Range("A1").Select
End Sub
 
Upvote 0
What is the error number & message, also what line is highlighted when you click debug?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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