Combining Macro's

DavidVernon

Board Regular
Joined
Jun 30, 2006
Messages
71
Hi everyone
I'm trying to combine the two macro's below so that they can be ran from one button. I'm struggling because of the scripting.dictionary. Because both macro's use this object, I'm not sure if it is possible to combine them. Any thoughts?

Sub delete_duplicate_invoice_values()

Dim Rng As Range, Dn As Range
Dim Txt As String, Ray
With CreateObject("scripting.dictionary")
.comparemode = vbTextCompare
Set Rng = Range(Range("U2"), Range("U" & Rows.Count).End(xlUp))
ReDim Ray(1 To Rng.Count, 1 To 3)
For Each Dn In Rng
Txt = Dn & Dn.Offset(, -20) & Dn.Offset(, -17)
If Not .Exists(Txt) Then
.Add Txt, ""
Else
Dn.Resize(, 1).ClearContents
End If
Next Dn
End With
End Sub

Sub delete_duplicate_credit_foc_values()

Dim Rng As Range, Dn As Range
Dim Txt As String, Ray
With CreateObject("scripting.dictionary")
.comparemode = vbTextCompare
Set Rng = Range(Range("T2"), Range("T" & Rows.Count).End(xlUp))
ReDim Ray(1 To Rng.Count, 1 To 3)
For Each Dn In Rng
Txt = Dn & Dn.Offset(, -19) & Dn.Offset(, -16)
If Not .Exists(Txt) Then
.Add Txt, ""
Else
Dn.Resize(, 1).ClearContents
End If
Next Dn
End With
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try

Code:
Sub delete_duplicate(ByVal Col As String)
    Dim Rng As Range, Dn As Range
    Dim Txt As String, Ray
    With CreateObject("scripting.dictionary")
        .comparemode = vbTextCompare
        Set Rng = Range(Cells(2, Col), Cells(Rows.Count, Col).End(xlUp))
        ReDim Ray(1 To Rng.Count, 1 To 3)
        For Each Dn In Rng
            Txt = Dn & Dn.EntireRow.Cells(1) & Dn.EntireRow.Cells(4)
            If Not .Exists(Txt) Then .Add Txt, "" Else Dn.ClearContents
        Next Dn
    End With
End Sub

Sub test()
    [B]delete_duplicate "U"
    delete_duplicate "T"[/B]
End Sub
 
Upvote 0
Thanks for answering EducatedFool - it looks so close, but my offset conditions change from one to the other. How could they be included?
 
Upvote 0
but my offset conditions change from one to the other. How could they be included?

I have not found any offset in my macro...

My macro is a complete analogue of 2 of your macros
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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