+ Reply to Thread
Results 1 to 3 of 3

Help - Insert method of Range class failed - Selection.Insert Shift:=xlToRight

Hybrid View

  1. #1
    Registered User
    Join Date
    06-13-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    2

    Help - Insert method of Range class failed - Selection.Insert Shift:=xlToRight

    Please help to debug, thanks!

    Sub Macro1()

    Application.DisplayAlerts = False
    Workbooks.OpenText Filename:="C:\CANADA\SAP_Reports\TOD.TXT", _
    Origin:=xlWindows, StartRow:=2, DataType:=xlDelimited, TextQualifier:= _
    xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
    Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 9), _
    Array(2, 1), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 9), Array(7, 2), Array(8, 2), _
    Array(9, 2), Array(10, 2), Array(11, 2), Array(12, 2), Array(13, 2), Array(14, 2), Array(15 _
    , 2), Array(16, 2), Array(17, 2), Array(18, 2), Array(19, 2), Array(20, 2), Array(21, 2), _
    Array(22, 2), Array(23, 2), Array(24, 2), Array(25, 2), Array(26, 2), Array(27, 1), Array( _
    28, 2), Array(29, 1), Array(30, 2), Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 1), _
    Array(35, 2), Array(36, 2), Array(37, 1), Array(38, 1), Array(39, 1), Array(40, 1), Array( _
    41, 1), Array(42, 1), Array(43, 1), Array(44, 1), Array(45, 1), Array(46, 1), Array(47, 1), _
    Array(48, 1), Array(49, 1), Array(50, 1), Array(51, 1), Array(52, 1), Array(53, 1), Array( _
    54, 1), Array(55, 2), Array(56, 1), Array(57, 2), Array(58, 2)), TrailingMinusNumbers _
    :=True
    ActiveCell.SpecialCells(xlLastCell).Select
    rrr = ActiveCell.Row
    Cells.Select
    Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    Cells.Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=33, Criteria1:="=US*", Operator:=xlOr, Criteria2:="=ca*"
    Cells.Select
    Selection.Copy
    Workbooks.Add
    ActiveSheet.Paste
    Cells.Select
    Cells.EntireColumn.AutoFit
    Range("A1").Select
    Application.CutCopyMode = False
    Columns("x:x").Select
    Selection.Insert Shift:=xlToRight
    Selection.NumberFormat = "General"
    Range("x1").Select
    Selection.NumberFormat = "@"
    ActiveCell.FormulaR1C1 = "Item"
    Range("x2").Select

    ActiveCell.FormulaR1C1 = "=TRIM(RC[-1])"
    Range("x2").Select
    Selection.Copy
    Range("x2:x" & rrr).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False

    ' Columns("x:x").Select
    Columns("W:W").Select
    Selection.Delete Shift:=xlToLeft
    Columns("Af:Af").Select
    Selection.Insert Shift:=xlToRight
    Selection.NumberFormat = "General"
    Range("Af1").Select
    ActiveCell.FormulaR1C1 = "Order Qty"
    Range("Af2").Select

    ActiveCell.FormulaR1C1 = "=RC[-1]*1"

    Range("Af2").Select
    Selection.Copy
    Range("Af2:Af" & rrr).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    Columns("Ae:Ae").Select
    Selection.Delete Shift:=xlToLeft
    Range("A1").Select
    Range("A1:Bd" & rrr).Sort Key1:=Range("AY2"), Order1:=xlDescending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal


    ActiveWorkbook.SaveAs Filename:="C:\CANADA\database\TOD.xls", FileFormat _
    :=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
    False, CreateBackup:=False
    '----------------------------------

    Workbooks.OpenText Filename:="C:\CANADA\SAP_Reports\TOD_P2P.TXT", _
    Origin:=xlWindows, StartRow:=7, DataType:=xlDelimited, TextQualifier:= _
    xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
    Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 9), _
    Array(2, 1), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 9), Array(7, 2), Array(8, 2), _
    Array(9, 2), Array(10, 2), Array(11, 2), Array(12, 2), Array(13, 2), Array(14, 2), Array(15 _
    , 2), Array(16, 2), Array(17, 2), Array(18, 2), Array(19, 2), Array(20, 2), Array(21, 2), _
    Array(22, 2), Array(23, 2), Array(24, 2), Array(25, 2), Array(26, 2), Array(27, 1), Array( _
    28, 2), Array(29, 1), Array(30, 2), Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 1), _
    Array(35, 2), Array(36, 2), Array(37, 1), Array(38, 1), Array(39, 1), Array(40, 1), Array( _
    41, 1), Array(42, 1), Array(43, 1), Array(44, 1), Array(45, 1), Array(46, 1), Array(47, 1), _
    Array(48, 1), Array(49, 1), Array(50, 1), Array(51, 1), Array(52, 1), Array(53, 1), Array( _
    54, 1), Array(55, 2), Array(56, 1), Array(57, 2), Array(58, 2)), TrailingMinusNumbers _
    :=True
    ActiveCell.SpecialCells(xlLastCell).Select
    rrr = ActiveCell.Row
    Cells.Select
    Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
    Cells.Select
    Selection.AutoFilter
    Selection.AutoFilter Field:=33, Criteria1:="=US*", Operator:=xlOr, Criteria2:="=ca*"
    Cells.Select
    Selection.Copy
    Workbooks.Add
    ActiveSheet.Paste
    Cells.Select
    Cells.EntireColumn.AutoFit
    Range("A1").Select
    Application.CutCopyMode = False
    Columns("y:y").Select
    Selection.Insert Shift:=xlToRight
    Selection.NumberFormat = "General"
    Range("y1").Select
    Selection.NumberFormat = "@"
    ActiveCell.FormulaR1C1 = "Item"
    Range("y2").Select
    ActiveCell.FormulaR1C1 = "=TRIM(RC[-1])"
    Range("y2").Select
    Selection.Copy
    Range("y2:y" & rrr).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    Columns("x:x").Select
    Selection.Delete Shift:=xlToLeft
    Columns("Ag:Ag").Select
    Selection.Insert Shift:=xlToRight
    Selection.NumberFormat = "General"
    Range("Ag1").Select
    ActiveCell.FormulaR1C1 = "Order Qty"
    Range("Ag2").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*1"
    Range("Ag2").Select
    Selection.Copy
    Range("Ag2:Ag" & rrr).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    Columns("Af:Af").Select
    Selection.Delete Shift:=xlToLeft
    Range("A1").Select
    Range("A1:Bd" & rrr).Sort Key1:=Range("AY2"), Order1:=xlDescending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal

    'New
    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft

    Range("A1:Bd" & rrr).Copy

    Windows("TOD.xls").Activate
    ARL1 = ActiveSheet.UsedRange.Rows.Count + 1
    ARL2 = "A" & ARL1
    Range(ARL2).Select
    ActiveSheet.Paste
    ActiveWorkbook.Save
    Cells.Select
    Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("H2") _
    , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
    False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
    :=xlSortNormal
    Range("A1").Select
    ActiveWorkbook.Save
    End Sub

  2. #2
    Registered User
    Join Date
    06-13-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    2

    Post Re: Help - Insert method of Range class failed - Selection.Insert Shift:=xlToRight

    Can anyone help me to fix this error on VBA? The debug is indicated to ' Selection.Insert Shift:=xlToRight '. Thanks so much!

  3. #3
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Help - Insert method of Range class failed - Selection.Insert Shift:=xlToRight

    You need to re-edit your message and wrap you code and code tags.
    Edit your message.
    Select your code.
    Click on the # icon.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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