combining macros - compile error: duplicate declaration in current scope

J

J.W. Aldridge

I have a problem where I've recorded many macros within a workbook and
I am trying to consolidate them so the workbook wont be so large and
have so many macros.
Instead of doing it this way:

Sub MainMacro()
run macro 1
run macro 2
run macro 3

End Sub

I began actually copyingt the codes and combining them. The problem I
get is when I run the final macro, I have to go back and put a number
in front of some commands like "Rng" & "String" to avoid the "compile
error: duplicate declaration in current scope."

Example code:

Dim Rng As Range, cell As Range
Dim s As String, s1 As String
Dim sChr As String, i As Long
Set Rng = Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
For Each cell In Rng

Any suggestions on combining macros? Or to avoid this particular error?
I sure hate going back trying to number each to separate them.

Thanx.
 
B

Bob Phillips

The workbook may be smaller, but the code will be a lot more unwieldy.

I would suggets you revert to your multiple macros.

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top