"Can't enter break mode at this time"

41 Views Asked by At

I'm trying to run a macro in Excel, but when VBA tries to run the first line of the code for adding a sheet, the error "Can't enter break mode at this time" appears. I don't know what I am doing wrong, can someone help me?

Sub hc_database()
    Sheets.Add After:=Worksheets("Mid-filled master w38")
    Sheet2.Name = "HC Database"
    Worksheets("Mid-filled master w38").Range("A1:k1812").Copy Destination:=Worksheets("HC Database").Range("A5")
    Sheet2.Columns("a:k").AutoFit
    Sheet2.Rows("1:1820").RowHeight = 14.5
    Sheet2.Range("l5:aw5") = "Volume"
    Sheet2.Range("L4") = "Week 37"
    Sheet2.Range("L4").Select
    Selection.AutoFill Destination:=Range("L4:AA4"), Type:=xlFillDefault
    Sheet2.Range("AB4") = "Week 1"
    Sheet2.Range("AB4").Select
    Selection.AutoFill Destination:=Range("AB4:AW4"), Type:=xlFillDefault
    Sheet1.Range(Sheet1.Cells(2, 12), Sheet1.Cells(49, 1812)).Copy Destination:=Sheet2.Range("l6")
    
    Dim i As Integer, LastCol As Range
    
    For i = 1 To 37
       Set LastCol = Sheet2.Range("L4").End(xlToRight)
       LastCol.Offset(0, 0).Resize(1, 8).Select
       Selection.EntireColumn.Insert Shift:=xlToRight
    Next i
     
    Dim inicio As Range
    Dim j As Integer
    Dim txt1 As String, txt2 As String, txt3 As String, txt4 As String, txt5 As String, txt6 As String, txt7 As String, txt8 As String
    txt1 = "Conformado"
    txt2 = "Corte"
    txt3 = "Doblado"
    txt4 = "Lavado"
    txt5 = "Mangueras"
    txt6 = "Soldado"
    txt7 = "Montaje"
    txt8 = "HC"
    
    Set inicio = Sheet2.Range("m5")
    
    inicio.Select
    For j = 1 To 38
        
            Selection.Resize(1, 8).Select
            Selection.Cells(1, 1) = txt1
            Selection.Cells(1, 2) = txt2
            Selection.Cells(1, 3) = txt3
            Selection.Cells(1, 4) = txt4
            Selection.Cells(1, 5) = txt5
            Selection.Cells(1, 6) = txt6
            Selection.Cells(1, 7) = txt7
            Selection.Cells(1, 8) = txt8
            Selection.End(xlToRight).Offset(0, 1).Select
    Next j
    
End Sub

I tried diverse solutions like typing "Stop" before adding the line but it didn't work.

0

There are 0 best solutions below