"can't execute code in break mode" MACRO VBA TO DEFINE NAME AND VLOOKUP FOR MULTIPLE SHEETS

SAQIBN

New Member
Joined
Oct 16, 2021
Messages
20
Office Version
  1. 2013
Platform
  1. Windows
I have recorded a Macro for a Workbook having 8 sheets!

But Error "can't execute code in break mode"

Macro is with Following Steps.

1: wherever I'm in sheets, Goto Sheet1
2: From Sheet1 to Sheet8, Assign Name Range to Specific 3 Columns B:D
3: Insert a New Sheet in Start With name: "Vlookup"
4: In "Vlookup" Sheet , Draw Formula :

Recorded macro is as below:

VBA Code:
Sub ATL_VLOOKUP()
'
' ATL_VLOOKUP Macro
'

'
Worksheets("Part1").Select





    Selection.End(xlUp).Select
    Columns("B:D").Select
    ActiveWorkbook.Names.Add Name:="TABLE1", RefersToR1C1:="=Part1!C2:C4"
    ActiveWorkbook.Names("TABLE1").Comment = ""
    ActiveSheet.Next.Select
    Selection.End(xlUp).Select
    Columns("B:D").Select
    ActiveWorkbook.Names.Add Name:="TABLE2", RefersToR1C1:="=Part2!C2:C4"
    ActiveWorkbook.Names("TABLE2").Comment = ""
    ActiveSheet.Next.Select
    Selection.End(xlUp).Select
        Columns("B:D").Select
    ActiveWorkbook.Names.Add Name:="TABLE3", RefersToR1C1:="=Part3!C2:C4"
    ActiveWorkbook.Names("TABLE3").Comment = ""
    ActiveSheet.Next.Select
    Selection.End(xlUp).Select
    Range("B1").Select
    Columns("B:D").Select
    ActiveWorkbook.Names.Add Name:="TABLE4", RefersToR1C1:="=Part4!C2:C4"
    ActiveWorkbook.Names("TABLE4").Comment = ""
    ActiveSheet.Next.Select
    Selection.End(xlUp).Select
    Columns("B:D").Select
    ActiveWorkbook.Names.Add Name:="TABLE5", RefersToR1C1:="=Part5!C2:C4"
    ActiveWorkbook.Names("TABLE5").Comment = ""
    ActiveSheet.Next.Select
    Selection.End(xlUp).Select
    Columns("B:D").Select
    ActiveWorkbook.Names.Add Name:="TABLE6", RefersToR1C1:="=Part6!C2:C4"
    ActiveWorkbook.Names("TABLE6").Comment = ""
    ActiveSheet.Next.Select
    Selection.End(xlUp).Select
    Columns("B:D").Select
    ActiveWorkbook.Names.Add Name:="TABLE7", RefersToR1C1:="=Part7!C2:C4"
    ActiveWorkbook.Names("TABLE7").Comment = ""
    ActiveSheet.Next.Select
    Selection.End(xlUp).Select
    Columns("B:D").Select
    ActiveWorkbook.Names.Add Name:="TABLE8", RefersToR1C1:="=Part8!C2:C4"
    ActiveWorkbook.Names("TABLE8").Comment = ""


    Sheets.Add(before:=Sheets("Part1")).Name = "Vlookup"
    
    
    Worksheets("Vlookup").Activate
    
    
    
    

    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[-1],TABLE1,2,0),IFERROR(VLOOKUP(RC[-1],TABLE2,2,0),IFERROR(VLOOKUP(RC[-1],TABLE3,2,0),IFERROR(VLOOKUP(RC[-1],TABLE4,2,0),IFERROR(VLOOKUP(RC[-1],TABLE5,2,0),IFERROR(VLOOKUP(RC[-1],TABLE6,2,0),IFERROR(VLOOKUP(RC[-1],TABLE7,2,0),IFERROR(VLOOKUP(RC[-1],TABLE8,2,0),""NOT FOUND""))))))))"
    
    
    

    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[-2],TABLE1,3,0),IFERROR(VLOOKUP(RC[-2],TABLE2,3,0),IFERROR(VLOOKUP(RC[-2],TABLE3,3,0),IFERROR(VLOOKUP(RC[-2],TABLE4,3,0),IFERROR(VLOOKUP(RC[-2],TABLE5,3,0),IFERROR(VLOOKUP(RC[-2],TABLE6,3,0),IFERROR(VLOOKUP(RC[-2],TABLE7,3,0),IFERROR(VLOOKUP(RC[-2],TABLE8,3,0),""NOT FOUND""))))))))"
    Range("C3").Select

End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi
VBA Code:
 Sheets.Add(before:=Sheets("Part1")).Name = "Vlookup"
    Worksheets("Vlookup").Activate

    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[-1],TABLE1,2,0),IFERROR(VLOOKUP(RC[-1],TABLE2,2,0),IFERROR(VLOOKUP(RC[-1],TABLE3,2,0),IFERROR(VLOOKUP(RC[-1],TABLE4,2,0),IFERROR(VLOOKUP(RC[-1],TABLE5,2,0),IFERROR(VLOOKUP(RC[-1],TABLE6,2,0),IFERROR(VLOOKUP(RC[-1],TABLE7,2,0),IFERROR(VLOOKUP(RC[-1],TABLE8,2,0),""NOT FOUND""))))))))"
    
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[-2],TABLE1,3,0),IFERROR(VLOOKUP(RC[-2],TABLE2,3,0),IFERROR(VLOOKUP(RC[-2],TABLE3,3,0),IFERROR(VLOOKUP(RC[-2],TABLE4,3,0),IFERROR(VLOOKUP(RC[-2],TABLE5,3,0),IFERROR(VLOOKUP(RC[-2],TABLE6,3,0),IFERROR(VLOOKUP(RC[-2],TABLE7,3,0),IFERROR(VLOOKUP(RC[-2],TABLE8,3,0),""NOT FOUND""))))))))"
    Range("C3").Select

When you add a new sheet will be activated then the Range A1 is the active cell
so you are inserting the formula in A1!!!
I guess you should select the desired cell instead of Worksheets("Vlookup").Activate
 
Upvote 0
Solution

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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