Link to home
Start Free TrialLog in
Avatar of Diane Lonergan
Diane LonerganFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel VBA Script

Hi,

Could anyone help me please with a piece of Excel Vba. I have attached a sample xlsx which has two sheets.

Sheet one (Before VBA) is my source data
Sheet two (After VBA) is my required result.

In a nutshell I have a spreadsheet of many thousands of rows. It is sorted by document id. Where the document id is not duplicated in the dataset, the only action required is to copy the entire row (as is) to the target sheet. Where a document id is repeated through several rows, these need to be reduced into one single row, with the unique cell value (pool) being moved from each of the duplicated rows to the first row and the  duplicate rows deleted. Hopefully that will make sense when you open the sample sheet.
sample.xlsx
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Subodh

Just change
Set sws = Sheet1

Open in new window

to
Set sws = Sheets(1)

Open in new window

@Macroshadow is there a reason why to change the code? I am not a VBA expert so I was just curious.
Sheet1 is the sheet code name and Sheets(1) will mean whatever sheet's index is 1.
I used Sheet1 code name because if user changes it's name, it will still refer to the same sheet.

Of course that can be tweaked as per the requirement.
Like
Set Sws = Sheets("Sheet1")

Open in new window

@Subodh thanks for the explanation. :)
You're welcome Edward! :)
Avatar of Diane Lonergan

ASKER

Thanks Subodh, I will give this a go.
Great solution Subodh, worked perfectly

Thanks
You're welcome Diane! Glad it worked.