jbesclapez
Active Member
- Joined
- Feb 6, 2010
- Messages
- 275
Hello,
I have a macro that adds up data in 5 columns (Q to W) to a column(AB) and Erase the duplicates data.
However, the problem with this macro is that it does not work when there is nothing in one of the column...
How can I solve that?
Thanks for your help
I have a macro that adds up data in 5 columns (Q to W) to a column(AB) and Erase the duplicates data.
However, the problem with this macro is that it does not work when there is nothing in one of the column...
Code:
Sub ThreeColDupes()
Dim MyDict As Object, MyCols As Variant, OutCol As String, LastRow As Long
Dim InputSh As Worksheet, OutputSh As Worksheet
Dim x As Variant, i As Long, MyData As Variant
Set MyDict = CreateObject("Scripting.Dictionary")
Set InputSh = Sheets("DB-Formules")
'Si il y a une colonne vide dans le Array en dessous alors la macro ne fonctionne pas
MyCols = Array("Q", "R", "S", "T", "U", "V", "W")
Set OutputSh = Sheets("DB-Formules")
OutCol = "AB"
For Each x In MyCols
LastRow = InputSh.Cells(Rows.Count, x).End(xlUp).Row
MyData = InputSh.Range(x & "1:" & x & LastRow).Value
For i = 1 To UBound(MyData)
If MyData(i, 1) <> "" Then MyDict(MyData(i, 1)) = 1
Next i
Next x
OutputSh.Range(OutCol & "1").Resize(MyDict.Count, 1).Value = WorksheetFunction.Transpose(MyDict.keys)
End Sub
How can I solve that?
Thanks for your help