Excel VBA Macro to Copy List but not Duplicate

Youseepooo

New Member
Joined
Feb 5, 2019
Messages
37
Hello,


I have a worksheet with many sheets that i would like to summarize into one sheet. Essentially i want to go through ranges $D$29:$D$39 and copy the list ( which includes a column of cells with texts & values ) however there are duplicates so i don't want the same cell value/text to appear twice on my summary sheet. I want it to do this for every sheet except 2 which are named "Ref" & "Summary" After going through every sheet's (excluding the 2 i mentioned) i would like it to paste all the values/text on the summary sheet in range
starting in column B31 of "Summary" sheet.

if it could paste it in alphabetical order that would be nice, but most importantly is to capture every different value/text (in all sheets excluding 2 sheets) for the summary sheet.

Thank You very much
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,301
Office Version
  1. 365
Platform
  1. Windows
How about
Code:
Sub Youseepooo()
   Dim Ws As Worksheet
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      .CompareMode = vbTextCompare
      For Each Ws In Worksheets
         If Ws.Name <> "Ref" And Ws.Name <> "Summary" Then
            For Each Cl In Ws.Range("D29:D39")
               .Item(Cl.Value) = Empty
            Next Cl
         End If
      Next Ws
      Sheets("Summary").Range("B31").Resize(.Count).Value = Application.Transpose(.Keys)
   End With
End Sub
 

Youseepooo

New Member
Joined
Feb 5, 2019
Messages
37
works good so far, it just seems to be picking up a null cell somewhere, is there a way to not make it display empty/null cells.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,301
Office Version
  1. 365
Platform
  1. Windows
Yup, like this
Code:
Sub Youseepooo()
   Dim Ws As Worksheet
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      .CompareMode = vbTextCompare
      For Each Ws In Worksheets
         If Ws.Name <> "Ref" And Ws.Name <> "Summary" Then
            For Each Cl In Ws.Range("D29:D39")
              [COLOR=#ff0000] If Cl.Value <> "" Then [/COLOR].Item(Cl.Value) = Empty
            Next Cl
         End If
      Next Ws
      Sheets("Summary").Range("B31").Resize(.Count).Value = Application.Transpose(.Keys)
   End With
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,301
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,123,318
Messages
5,600,917
Members
414,416
Latest member
Nobu

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
Top