whats wrong with this code?

Sub HideGroupBox()
If Cells(1, "I").Value = "2" Then
DayBox.Visible = False
Else
DayBox.Visible = True
End If
End Sub

im trying to hide a group box with options if the value in L1 = 2 but in not sure what im doing wrong




Answer this question

whats wrong with this code?

  • Alexnaldo Santos

    Hello,

    What magical is saying, is to put the statement Msgbox(cells(1,"l").value) before each line that states DayBox.visible=..

    This will display the value of cells(1,"l") before executing the next command.

    As for me I still dont understand the GroupBox, do you mean Frame, are you using Excel, a Userform or embedding this in the sheet.

    Or maybe post more of your code, it will help understand the code a bit more.

    Chas


  • Asbj0rn

    with the code

    Sub HideGroupBox()
    If Cells(1, "I").Value = "2" Then

    msgbox "hello"
    DayBox.Visible = False
    Else

    msgbox "hello else"
    DayBox.Visible = True
    End If

    msgbox "end"
    End Sub

    it says hello then it says run time error '424' object required

    and hilights DayBox.Visible = False in yellow.

    any more help



  • WV John

    Try msgbox "Blah 1" and msgbox "Blah else" before DayBox command. It will be easier to debug.
  • WIL PANNELL

    Ok use this.

    ActiveSheet.Shapes("DayBox").Visible = False

    And modify the other one as well.

    I assume you are only changing the name of the group. You need ActiveSheet.Shapes("Group Nmae") to obtain the object before you use it. Just like you can't say A1.Value = 123, you have to use Range("A1").Value = 123 or

    Dim This_is_a_range_object as Range

    Set This_is_a_range_object = new Range()

    to have a valid object to use.


  • wino

    Hello,

    Don't know what your DayBox is but it could be that your comparison is not correct.

    Is the value in Cells(1,"l") a number or string If it is a number then this will not evaluate to be true, you need to say write if cells(1,"l").value=2

    Chas


  • MarcGBeauchamp

    daybox is the name of the box i placed around the options, its a group box, not sure if i was using the write code, i did try what u said but to no joy.

  • RPKJBP

    could you please be more specific not sure where im ment to write this.

  • Janne_K

    Hello, try this

    Sub HideGroupBox()
    If Cells(1, "I").Value = "2" Then

    msgbox "hello"
    DayBox.Visible = False
    Else

    msgbox "hello else"
    DayBox.Visible = True
    End If

    msgbox "end"
    End Sub

    If it doesn't print "hello" or "hello else", there is a problem to your comparison statement. If is doesn't print "end", but print either "hello" or "hello else", that means there is a problem about your DayBox command.

    BTW, did you declare and initialize DayBox variable anywhere


  • whats wrong with this code?