Require macro

Ron99

Active Member
Joined
Feb 10, 2010
Messages
347
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I need a macro to remove duplicates by row and also remove the blanks. Its a huge data by rows and columns
below example - duplicates "Rob & "goal" to be removed, but should retain unique and remove the blanks

[TABLE="width: 500"]
<tbody>[TR]
[TD]gulf[/TD]
[TD]Rob[/TD]
[TD][/TD]
[TD][/TD]
[TD]stat[/TD]
[TD]Rob[/TD]
[TD]aim[/TD]
[TD]hero[/TD]
[TD]fun[/TD]
[TD]goal[/TD]
[TD]view[/TD]
[TD]review[/TD]
[TD][/TD]
[TD]page[/TD]
[TD]goal[/TD]
[/TR]
</tbody>[/TABLE]


Output -


[TABLE="width: 500"]
<tbody>[TR]
[TD]gulf[/TD]
[TD]Rob[/TD]
[TD]stat[/TD]
[TD]aim[/TD]
[TD]hero[/TD]
[TD]fun[/TD]
[TD]goal[/TD]
[TD][/TD]
[TD]view[/TD]
[TD]review[/TD]
[TD]page[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Yes, That's correct. Row 4 to be copied to row 1 and then row 5 to be copied to row 4.
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
How about
Code:
Sub CopyDatatoOneRow()

   Dim Cl As Range

   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A1", Cells(1, Columns.Count).End(xlToLeft))
         If Not .exists(Cl.Value) Then .Add Cl.Value, Nothing
      Next Cl
      For Each Cl In ActiveSheet.UsedRange.Offset(1).Resize(ActiveSheet.UsedRange.Rows.Count - 1)
         If .exists(Cl.Value) Then
            Cl.ClearContents
            Intersect(Cl.EntireRow, ActiveSheet.UsedRange).SpecialCells(xlConstants).Copy Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)
            Cl.EntireRow.ClearContents
         End If
      Next Cl
      .removeall
   End With
   Columns(1).SpecialCells(xlBlanks).EntireRow.Delete
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A1").CurrentRegion.Offset(1)
         If Not Cl.Value = "" And Not .exists(Cl.Value) Then .Add Cl.Value, Nothing
      Next Cl
      Range("A2").Resize(, .Count).Value = .keys
      Rows("3:1048576").Delete
   End With
         
End Sub
 
Upvote 0
Hello,

I run the code and got the error message

Run time error - 438

Object doesn't support this property or method.
 
Upvote 0
Which line of code gave that error?
 
Upvote 0
Hello,

Error is on this line

Range("A2").Resize(, .Count).Value = .keys
 
Upvote 0
Have you changed the code at all?
 
Upvote 0
I did try changing to - Sheets("Test1").Range("A2").Resize(, .Count).Value = .keys. which did not help. I have a very limited knowledge with Macro, if you can assist that will be a great help.

This code - Sub CopyDatatoOneRow() works absolutely fine for the 1st row in the database but doesn't proceed further for the remaining rows.

Thank you.
Ron
 
Upvote 0
Could you supply a sample of the data when it's failing? As I cannot replicate the error.
 
Upvote 0

Forum statistics

Threads
1,223,638
Messages
6,173,492
Members
452,516
Latest member
druck21

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