Shereen Shousha

New Member
Joined
Dec 12, 2017
Messages
3
Hi all, i'm new to VBA so I do need some help. I'm trying to create some macros to help me accelerating my repeatable steps in my workbook. I have just got the way to correct the duplication when it occur but I hope you can help me to find a way to prevent it from happening. Here is the details to my macro. thanks

Sub Copy_Data()
'
' Copy_Data Macro
'
'
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Copy
Workbooks.Open Filename:="C:\Users\Said\Documents\Dubai VBA\VBA\Orders.xlsx" _
, Origin:=xlWindows
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.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, _
7), Header:=xlNo

ActiveWindow.Close savechanges:=True

Application.CutCopyMode = False
Range("A1").Select
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Welcome to the Board!

Please explain how you are defining "data duplication" and how it involves the macro you've posted.
Explain the whole process, and how you envision it working.

Are you trying to copy a whole range of data and want to prevent duplicate rows from appearing?
If so, this not an easy task (if you are copying whole ranges), and I would simply remove the duplicates afterwards (it is a whole lot easier to do it that way).
Is there some reason you don't want to do it that way?
 
Upvote 0
you might try conditional format and set up the column that highlights a duplicate, catch them as they are entered, and works all the time
 
Upvote 0
Hi Joe, thank you for your help.
I'm creating several macros to combine in one macro to have an automated way of copying modified date of a certain range (example: a monthly date) from a monthly test file to an excel workbook representing the updated monthly report. So every month the data in the text file should be automatically uploaded into the monthly report by adding it to the end of the sheet month after another.


I do that through macro as I said, so the macro run to format the data, copy it and past it in the sheet. If the macro run more than once it can cause a data duplication. So as a corrective action I added the instructions as follows:

Selection.CurrentRegion.RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, _
7), Header:=xlNo

I wonder if there's another instruction that can be inserted instead to prevent it from happening originally. I imagine having an instruction checking if this specific month (lets say Nov-17) already exist? IF YES, then end process and may be pop up message saying Data already updated, and IF NO continue with the macro to update the data for this month.

this is the idea, but what is the proper code for it?
thanks
 
Upvote 0
I wonder if there's another instruction that can be inserted instead to prevent it from happening originally. I imagine having an instruction checking if this specific month (lets say Nov-17) already exist? IF YES, then end process and may be pop up message saying Data already updated, and IF NO continue with the macro to update the data for this month.
If you can clearly define the logic for checking for that, we should be able to write code to do that.
We will need specific details.
 
Upvote 0
In looking at your macros & files, how can you, by looking at it, determine if there are duplicates before you load them?
Is there some sheet or file that exists or has records already?
If so, what is its location/name?
How can you match up your data to the correct name/sheet?

Remember, we know nothing about your project other than what you have told us here. If you only give us very general information, we can only give you general responses.
But if you give us detailed information, the greater the chance that we can give you code that will do what you want with minimal modification on your side.
 
Upvote 0

Forum statistics

Threads
1,221,442
Messages
6,159,905
Members
451,601
Latest member
terrynelson55

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