If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Macro / Compile Error / Duplicate Declaration
I am trying to modify my macro to perform the same operations twice - I am
trying to do this by copying/paste the macro and making some changes to the copied macro. When I try and run the macro, I get a compiler error "Duplicate Declaration In Current Scope" - the macro stops at the line marketed with *** below. Is there a way to modify the macro to get it to work ? Thank you in advance 'find engine 2 part A Sheets("A").Select Dim rng As Range Set rng = _ Columns(7).Find(What:="1", After:=Cells(Rows.Count, "g"), _ LookIn:=xlFormulas, LookAt:=xlWhole, _ SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _ MatchCase:=False) If Not rng Is Nothing Then rng.Select Else MsgBox "1 not found" End If 'cut engine 2 ' Range("G12816").Select (old code) rng.Offset(1, 0).Select Range(Selection, Selection.End(xlToLeft)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Cut Sheets("2").Select Range("A1").Select ActiveSheet.Paste Sheets("A").Select Range("H1:I1").Select Selection.Copy Sheets("2").Select Range("H1").Select ActiveSheet.Paste Range("F1:G1").Select Range("G1").Activate Range(Selection, Selection.End(xlDown)).Select Application.CutCopyMode = False Selection.ClearContents Sheets("A").Select Range("F1:G1").Select Range("G1").Activate Range(Selection, Selection.End(xlDown)).Select Selection.ClearContents Sheets("A").Select Range("A1").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlToRight)).Select Range("A1:I11496").Select Selection.Cut Sheets("1").Select Range("A1").Select ActiveSheet.Paste 'find engine 2 part B Sheets("B").Select **** Dim rng As Range **** Set rng = _ Columns(7).Find(What:="1", After:=Cells(Rows.Count, "g"), _ LookIn:=xlFormulas, LookAt:=xlWhole, _ SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _ MatchCase:=False) If Not rng Is Nothing Then rng.Select Else MsgBox "1 not found" End If 'cut engine 2 ' Range("G12816").Select (old code) rng.Offset(1, 0).Select Range(Selection, Selection.End(xlToLeft)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Cut Sheets("2").Select Range("A1").Select Range(Selection, Selection.End(xlDown)).Select ActiveSheet.Paste. |
#2
|
|||
|
|||
Good evening Carl The problem is that you're DIMming the variable rng twice and that's not allowed. That's not to say you can't load rng twice with two different values in the same routine - obviously, providing the first value you load in there is no longer needed.But only DIM it once. If you want two distinct values you could call the second rng variable rng1, and remember to change subsequent lines to make sure that they call the right variable. HTH DominicB -- dominicb ------------------------------------------------------------------------ dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932 View this thread: http://www.excelforum.com/showthread...hreadid=383269 |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Playing a macro from another workbook | Jim | General Discussion | 1 | February 23rd, 2005 10:12 PM |
Keyboard Shortcut Only Runs Part of the Macro | Jonnyboy117 | General Discussion | 2 | July 14th, 2004 08:27 PM |
Need Entry Point 18 Help On Access Executable File | Jeff Conrad | General Discussion | 26 | July 14th, 2004 06:00 AM |
Macro when a font in a range changes | whisperinghill | General Discussion | 0 | June 14th, 2004 07:21 PM |
Macro command go to last filled cell in column? | PatsyB. | Setting up and Configuration | 1 | May 17th, 2004 08:09 PM |