+ Reply to Thread
Results 1 to 3 of 3

Stumped - What am I doing wrong?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146

    Question Stumped - What am I doing wrong?

    On a workbook I'm making, I'm trying to have a customizable interface that will hide items as the user desires, however, I get an error calling the program I want to run across sheets. Thing that bothers me about this is I know both programs work if I run them independently. I also know that programs can run across sheets. Where am I going wrong?

    Private Sub CheckBox1_Click()
    Application.ScreenUpdating = False
    If CheckBox1 = True Then
    Range("a18").Select
    Selection.EntireRow.Hidden = False
    CommandButton7.Visible = True
    Call Sheets("Overview").special
    Else
    If Worksheets("overview").Range("b58").Value = 0 And Worksheets("overview").Range("c58").Value = 0 Then
    Range("a18").Select
    Selection.EntireRow.Hidden = True
    CommandButton7.Visible = False
    Call Sheets("overview").special
    Else
    Application.ScreenUpdating = True
    MsgBox ("The object you have choosen to hide contains values and thus can't be hidden.")
    End If
    End If
    End Sub

    *Other sheet*

    Public Sub special()
    If Sheets("summary").CheckBox1 = True Then
    Range("a61").Select
    Selection.EntireRow.Hidden = False
    Else
    Range("a61").Select
    Selection.EntireRow.Hidden = True
    End If
    End Sub

    *Edit - More info*

    The specific error I get when I try to run the program is:

    Runtime Error "1004"
    Select method or Range class failed.

    What does that mean?

  2. #2
    Registered User
    Join Date
    08-22-2005
    Posts
    4
    You don't need to call a seperate procedure to do this. You could simply use:

    Private Sub CheckBox1_Click()
    Application.ScreenUpdating = False
    If CheckBox1 = True Then
    Rows(18).Hidden = False
    CommandButton7.Visible = True
    Sheets("Overview").Rows(61).Hidden = False
    Else
    If Worksheets("overview").Range("b58").Value = 0 And Worksheets("overview").Range("c58").Value = 0 Then
    Rows(18).Hidden = True
    CommandButton7.Visible = False
    Sheets("Overview").Rows(61).Hidden = True
    Else
    Application.ScreenUpdating = True
    MsgBox ("The object you have choosen to hide contains values and thus can't be hidden.")
    End If
    End If
    End Sub

    Otherwise if you really want to have the seperate procedure, as it is not worksheet event code it should be stored in a Module and not a worksheet code sheet. Add a module and change the macro to:

    Public Sub special()
    With Sheets("overview")
    If Sheets("summary").CheckBox1 = True Then
    .Range("a61").EntireRow.Hidden = False
    Else
    .Range("a61").EntireRow.Hidden = True
    End If
    End With
    End Sub

    Then in your Checkbox Click event you can reference it as:
    Call Special

    Hope this helps.
    Rowan

  3. #3
    Forum Contributor
    Join Date
    09-02-2005
    Posts
    146
    Worked great. Thanks for the help!

+ 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