Consulting

Results 1 to 4 of 4

Thread: Run Time errror 1004

  1. #1
    VBAX Regular
    Joined
    Jan 2007
    Posts
    42
    Location

    Run Time errror 1004

    Hi everyone.... The following code asks the user to enter the :

    operator name,
    month,
    year,

    once the user enters these parameters they press a button and all the worksheets that are initially hidden become unhidden....

    With the exception of April, june, sept, november and february all sheets are displayed... For these months above, certain sheets are hidden, which are days 31 (as these months do not have 31 days)

    where the is .. is where the code i think is giving me an error:

    it says:

    run time error '1004'
    unable to set the hidden property of range class..


    this has got me buggered.... any reason why this happens... i commented the section out.. and the code runs propertly.... but this has got me puzzeled..... any help or have i done something wrong?? any help would be highly appreciated





    [VBA]Private Sub CommandButton1_Click()
    Dim wbpath$, oprtr$, mnth$, yr$
    Dim Sht As Worksheet
    ' name new workbook according to file path to which original was saved and add Operator, Month, and Year to name
    Application.ScreenUpdating = False
    If Range("f24") = "-" Then
    MsgBox "Operator name must be entered"
    Exit Sub
    End If
    If Range("f26") = "-" Then
    MsgBox "Month must be entered"
    Exit Sub
    End If
    If Range("f27") = "-" Then
    MsgBox "Year must be entered"
    Exit Sub
    End If
    With Sheets("cover sheet")
    oprtr$ = .Range("f24")
    mnth$ = .Range("f26")
    yr$ = .Range("f27")
    End With
    Sheets("Cover Sheet").Shapes("CommandButton1").Delete
    For Each Sht In ActiveWorkbook.Worksheets
    If Sht.Name <> "Cover Sheet" Then Sht.Visible = True
    Next
    Application.Run "rename_sheets"
    Application.Run "hidefirstlast"
    Dim fn As String
    fn = Dir(ActiveWorkbook.Path & "\Cash Reconciliation " & oprts$ & " " & mnth$ & " " & yr$ & ".xls")
    If Len(fn) Then
    MsgBox "File already exists"
    Exit Sub
    End If
    ThisWorkbook.SaveAs Application.ActiveWorkbook.Path & "\Cash Reconciliation " & oprtr$ & " " & mnth$ & " " & yr$ & ".xls"
    Application.ScreenUpdating = True


    If Range("f26") = "April" Then
    Sheet36.Visible = False
    Sheet1.Range("40:40").EntireRow.Hidden = True
    End If
    If Range("f26") = "June" Then
    Sheet36.Visible = False
    Sheet1.Range("40:40").EntireRow.Hidden = True
    End If
    If Range("f26") = "September" Then
    Sheet36.Visible = False
    Sheet1.Range("40:40").EntireRow.Hidden = True
    End If
    If Range("f26") = "November" Then
    Sheet36.Visible = False
    Sheet1.Range("40:40").EntireRow.Hidden = True
    End If
    If Range("f26") = "February" Then
    Sheet36.Visible = False
    Sheet35.Visible = False
    Sheet1.Range("39:40").EntireRow.Hidden = True
    End If

    End Sub[/VBA]

  2. #2
    VBAX Regular
    Joined
    Jan 2007
    Posts
    42
    Location
    Ohhhh.. another thing I forgot to mention

    where it says

    Sheet1.Range("40:40").EntireRow.Hidden = True

    that particular sheet is protected


    I tried writing the code to automatically unprotect it then hide it.... is it:


    If Range("f26") = "April" Then
    Sheet36.Visible = False


    With Worksheets("Cover Sheet")
    .Unprotect Password:="cbs"
    Sheet1.Range("40:40").EntireRow.Hidden = True
    .Protect Password:="cbs"


    I tried the above for april... but it still doesnt work

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    try the following code

    [VBA]With Worksheets ("CoverSheet")
    .UnProtect "CBS"
    Sheet1.Range("40:40").EntireRow.Hidden = True
    .Protect "cbs"[/VBA]
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by cbs81
    Sheet1.Range("40:40").EntireRow.Hidden = True
    Only needs

    Sheet1.Rows(40).Hidden = True

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •