macro runs from VBA toobar but not from command button

  • Hi. This code deletes rows from four sheets before moving on to something else. BUT when I add the code to a Command Button (2003 and 2007) the "Rows("2:600").Select" lines give a Runtime error 1004: Select Method of Range Class Failed error message. Any help would be GREATLY appreciated. :confused:

  • Re: macro runs from VBA toobar but not from command button


    There's generally no need to select things but if you do you need to qualify the range with the sheet to which it belongs:

    Code
    Worksheets("Sort by station").Rows("2:600").Delete Shift:=xlUp
    Worksheets("Sort by use").Rows("2:600").Delete Shift:=xlUp
    Worksheets("Sort condition & mileage").Rows("2:600").Delete Shift:=xlUp
    Worksheets("Sort by make model").Rows("2:600").Delete Shift:=xlUp
     
    With Worksheets("Add_edit_remove")
       .Select
       .Range("A5").Select
    End With

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!