+ Reply to Thread
Results 1 to 5 of 5

get "run time error 1004" when i try to activate macro on protected sheet why?

  1. #1
    Registered User
    Join Date
    01-05-2013
    Location
    Israel
    MS-Off Ver
    Excel 2010
    Posts
    12

    get "run time error 1004" when i try to activate macro on protected sheet why?

    for example:

    Private Sub cmdOK_Click()
    ActiveWorkbook.Sheets("זמנת מוצרים").Activate
    Range("A1").Select
    Do
    If IsEmpty(ActiveCell) = False Then
    ActiveCell.Offset(1, 0).Select
    End If
    Loop Until IsEmpty(ActiveCell) = True

    If txtName.Text = "" Then
    MsgBox "Please Enter Name", vbOKOnly, "Name Error!"
    Exit Sub
    ElseIf txtPhone.Text = "" Then
    MsgBox "Please Enter Phone", vbOKOnly, "Name Error!"
    Exit Sub
    ElseIf cboCourse1.Text = "" Then
    MsgBox "Please Enter Number Of Products", vbOKOnly, "Name Error!"
    Exit Sub

    ElseIf cboCourse.Text = "" Then
    MsgBox "Please Enter Product", vbOKOnly, "Name Error!"
    Exit Sub






    End If



    If IsNumeric(txtName.Value) And txtName.Value <> vbNullString Then

    MsgBox "Sorry, only TXT allowed"

    txtName.Value = vbNullString

    End If
    If Not IsNumeric(txtName.Value) And txtName.Value <> vbNullString Then


    ActiveCell.Offset = txtName.Value ---------------------------------------> this the line i get yellow in debug mode

    End If

    If IsNumeric(txtPhone.Value) And txtPhone.Value <> vbNullString Then


    C = txtPhone.Value
    ActiveCell.Offset(0, 1) = C

    End If
    If Not IsNumeric(txtPhone.Value) And txtPhone.Value <> vbNullString Then

    MsgBox "Sorry, only numbers allowed"

    txtPhone.Value = vbNullString

    End If


    If IsNumeric(cboCourse1.Value) And cboCourse1.Value <> vbNullString Then

    Dim A As Integer

    A = cboCourse1.Value
    ActiveCell.Offset(0, 4) = A

    End If
    If Not IsNumeric(cboCourse1.Value) And cboCourse1.Value <> vbNullString Then

    MsgBox "Sorry, only numbers allowed"

    cboCourse1.Value = vbNullString

    End If

    ActiveCell.Offset(0, 2) = cboDepartment.Value
    ActiveCell.Offset(0, 3) = cboCourse.Value


    If optIntroduction = True Then
    ActiveCell.Offset(0, 5).Value = "ינואר"
    ElseIf optIntermediate = True Then
    ActiveCell.Offset(0, 5).Value = "פבואר"
    ElseIf Opt1 = True Then
    ActiveCell.Offset(0, 5).Value = "מרץ"
    ElseIf Opt2 = True Then
    ActiveCell.Offset(0, 5).Value = "אפריל"
    ElseIf Opt3 = True Then
    ActiveCell.Offset(0, 5).Value = "מאי"
    ElseIf Opt4 = True Then
    ActiveCell.Offset(0, 5).Value = "יוני"
    ElseIf Opt5 = True Then
    ActiveCell.Offset(0, 5).Value = "יולי"
    ElseIf Opt6 = True Then
    ActiveCell.Offset(0, 5).Value = "אוגוסט"
    ElseIf Opt7 = True Then
    ActiveCell.Offset(0, 5).Value = "ספטמבר"
    ElseIf Opt8 = True Then
    ActiveCell.Offset(0, 5).Value = "אוקטבר"
    ElseIf Opt9 = True Then
    ActiveCell.Offset(0, 5).Value = "נובמבר"

    Else
    ActiveCell.Offset(0, 5).Value = "דצמבר"
    End If

    Range("A1").Select
    If Not cboCourse1.Value = vbNullString And txtPhone.Value = vbNullString Then

    ActiveCell.Offset(0, 2) = ""
    ActiveCell.Offset(0, 3) = ""
    ActiveCell.Offset(0, 5).Value = ""

    End If









    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: get "run time error 1004" when i try to activate macro on protected sheet why?

    Why? Because the sheet is protected and you are trying to change it. Unprotect it first, do your stuff, protect it again.

    Or use .Protect UserInterfaceOnly:=True, though that is not my preferred choice.


    Regards, TMS



    PS:Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-05-2013
    Location
    Israel
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: get "run time error 1004" when i try to activate macro on protected sheet why?

    ok thanks a lot

    but if i want to give to someone else so he will cant edit cell, how do i protect than?

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: get "run time error 1004" when i try to activate macro on protected sheet why?

    Thanks for the rep.

    Under normal circumstances, the worksheet will be protected and the cell can't be changed. When you press the button, the sheet will be unprotected, you make whatever changes you need and then you re-protect the worksheet ... all under control of the macro. Ideally, don't unprotect at the beginning and re-protect at the end, just around the actual changes ... and you could do that more than once just to limit the amount of time during which the sheet is unprotected.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    01-05-2013
    Location
    Israel
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: get "run time error 1004" when i try to activate macro on protected sheet why?

    ok
    got it
    tnx again

+ 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