Error 1004!!! WTF

MonkeyDeath

Board Regular
Joined
Jul 19, 2007
Messages
62
Right ive got this code

Code:
    ActiveWindow.SmallScroll Down:=-9
    Range("A20:AG27").Select
    ActiveSheet.Unprotect Password:="wyg"
    Range("A1:AG60").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    Range( _
        "U57:AG60,K59:R59,K57:R57,C53:F53,C51:F51,C49:F49,C47:F47,C45:F45,J45:AA46,J47:AA48,J49:AA50,J51:AA52,J53:AA54,AD45:AF45,AD47:AF47,AD49:AF49,AD51:AF51,AD53:AF53,A36:AG40,G41:J41,A28:AG35,A20:AG27,AB16:AF16,AB14:AF14" _
        ).Select
    Range("AB14").Activate
    Selection.Locked = False
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:= _
        False
    Range("A20:AG27").Select
    Sheets("Job (1)").Select
    Sheets("Job (1)").Copy Before:=Sheets(1)
    ActiveSheet.Unprotect Password:="wyg"
    Range("A1:AG60").Select
    Selection.Locked = True
    Selection.FormulaHidden = False
    Union(Range( _
        "F12:S12,F10:S10,F8:S8,F6:S6,H4:K4,F2,G2,H2,I2,S2:U2,S3:U3,S4:U4,U57:AG60,K59:R59,K57:R57,C53:F53,C51:F51,C49:F49,C47:F47,C45:F45,J45:AA46,J47:AA48,J49:AA50,J51:AA52,J53:AA54,AD45:AF45,AD47:AF47,AD49:AF49,AD51:AF51,AD53:AF53,A36:AG40,G41:J41" _
        ), Range( _
        "A28:AG35,A20:AG27,U19:W19,Z19:AB19,AB16:AF16,AB14:AF14,AB12:AF12,AB10:AF10,K16:P16,S16:T16,D16:E16,F14:S14" _
        )).Select
    Range("S4").Activate
    Selection.ClearContents
    Selection.Locked = False
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:= _
        False
    Range("H4:K4").Select
    ActiveWorkbook.Save

and it works fine when running it manually

ive created a command button with the design tool in VB editor,

i copied and pasted this in to the buttons VB script

when it gets to

Code:
Range("A1:AG60").Select

its stopps and comes up with error 1004 Select meathod of range class failed

then when i click on the manual way to run it ot dosnt stop me from clicking on the cells i want protected but it stops me from editing them,

any ideas
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
This may be a copout, but sometimes I find it easier to just resolve a problem without actually fixing it.

If the macro works fine, but when the code is pasted in the button click event doesn't work, Maybe try just calling the macro from the button click..

Code:
Private Sub CommandButton1_Click()
application.run "macroname"
End Sub
 
Upvote 0
Since all your ranges don't have a worksheet reference then VBA will be looking at ranges on the active sheet.

Also VBA could possibly be regarding the button as the Selection.
 
Upvote 0
Jommo, thanks that did the trick, that was what i was after to do anyway i prefer to cheat my way round thnigs if i can

you star
 
Upvote 0

Forum statistics

Threads
1,222,017
Messages
6,163,411
Members
451,835
Latest member
kristianb63

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