Hello all,
Note: It should also be noted that, when "splitting" the macros below up into two different macros, they work, but then I have to play 2 macros when I only want to play one.
Just when I thought I was getting this macro stuff, I've come back to reality. I tried to combine these 2 macros together (taking out 1 "sub" and 1 "end sub") and when doing so, I got the error message
"duplicate declaration in current scope"
I thought about removing some "Dim" lines, but realized that the Dims say different things. For example in macro 1, it says "Dim Rng As Range" and in macro 2, it says "Dim Cust As Range".
Don't I need both? Do I put in an "exit sub"?
thanks much
Sub macro1()
Dim Rng As Range
Dim i As Long
Dim what As Variant
what = Array("Cherry")
For i = 0 To UBound(what)
Do
Set Rng = ActiveSheet.UsedRange.Find(what(i))
If Rng Is Nothing Then
Exit Do
Else
Rows(Rng.Row).Delete
End If
Loop
Next i
'this was part of another macro, but when combining this one below with macro 1, it
'didn't work. I got the error message "duplicate declaration in current scope".
'sub macro2
Dim Cust As Range
Dim Blanks As Range
Dim Key As Variant
Dim DSO As Object
Dim Rng As Range
Dim RngEnd As Range
Rows("4:4").Select
Application.CutCopyMode = False
Selection.Copy
Selection.Insert Shift:=xlDown
Set Cust = ActiveSheet.Rows(1).Find("Customer", , xlValues, xlPart, xlByRows, xlNext, False)
Set Rng = Cust.Offset(1, 0)
Set RngEnd = Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Cust = IIf(RngEnd.Row < Rng.Row, Rng, Rng.Parent.Range(Rng, RngEnd))
Application.ScreenUpdating = False
Set DSO = CreateObject("Scripting.Dictionary")
DSO.CompareMode = vbTextCompare
For Each cell In Cust.Cells
Key = Trim(cell)
If Not DSO.Exists(Key) Then
DSO.Add Key, 1
Else
cell.ClearContents
End If
Next cell
If DSO.Count > 0 Then
Set Blanks = Cust.SpecialCells(xlCellTypeBlanks)
Blanks.EntireRow.Delete
End If
Set DSO = Nothing
Application.ScreenUpdating = True
End Sub
Bookmarks