Results 1 to 13 of 13

Combining two macros results in error message

Threaded View

duugg Combining two macros results... 06-30-2009, 02:16 PM
DonkeyOte Re: Combining two macros... 06-30-2009, 03:18 PM
duugg Re: Combining two macros... 06-30-2009, 05:19 PM
DonkeyOte Re: Combining two macros... 06-30-2009, 06:05 PM
duugg Re: Combining two macros... 06-30-2009, 06:45 PM
  1. #1
    Valued Forum Contributor
    Join Date
    04-11-2006
    MS-Off Ver
    2007
    Posts
    438

    Combining two macros results in error message

    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
    Last edited by duugg; 07-01-2009 at 02:43 PM. Reason: additional thoughts/comments

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1