0
votes

Hi i have recorded a macro and i want to implement it into my current vba macro, however upon testing the code with the button on another sheet, there seem to be an

error 1004 which states Select method of range class failed

highlighting the selection part of the code." Sheets("Raw").Cells.Select " did i miss out anything in my code or is there any suggestion. Thanks in advance !

Private Sub CommandButton1_Click()
' unmerge Macro
' Keyboard Shortcut: Ctrl+q

Sheets("Raw").Cells.Select
Selection.unmerge
    With Selection
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
        End With

    Sheets("Raw").Rows("1:5").Select
    Selection.Delete Shift:=xlUp
    Sheets("Raw").Cells.Select
    Selection.ColumnWidth = 8.29
    Sheets("Raw").Range("C:C,E:F,H:H,J:M,O:R,T:T,V:W,Y:AA").Select
    Sheets("Raw").Range("Y1").Activate

    Sheets("Raw").Range( _
        "C:C,E:F,H:H,J:M,O:R,T:T,V:W,Y:AA,AC:AD,AF:AH,AJ:AJ,AL:AM,AO:AO,AQ:AR,AT:AU"). _
        Select
    Sheets("Raw").Range("AT1").Activate

    Sheets("Raw").Range( _
        "C:C,E:F,H:H,J:M,O:R,T:T,V:W,Y:AA,AC:AD,AF:AH,AJ:AJ,AL:AM,AO:AO,AQ:AR,AT:AU,AW:AY" _
        ).Select
   Sheets("Raw").Range("AW1").Activate
    Selection.Delete Shift:=xlToLeft
    Sheets("Raw").Range("AG23").Select

    Sheets("Raw").Cells.Select
    Selection.ColumnWidth = 9.71
    Selection.ColumnWidth = 13.71
    Sheets("Raw").Range("D14").Select
End Sub
1
Have you seen this poast before? If not have a look before doing anymore coding... stackoverflow.com/questions/10714251/… - alowflyingpig

1 Answers

1
votes

If you are using .Select on cells then the sheet of those cells must be active. Add this on the first line:

Sheets("Raw").Activate