whats wrong with this code?  
Author Message
milkshake





PostPosted: Visual Basic for Applications (VBA), whats wrong with this code? Top

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




Microsoft ISV Community Center Forums2  
 
 
ChasAA





PostPosted: Visual Basic for Applications (VBA), whats wrong with this code? Top

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


 
 
milkshake





PostPosted: Visual Basic for Applications (VBA), whats wrong with this code? Top

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.

 
 
magicalclick





PostPosted: Visual Basic for Applications (VBA), whats wrong with this code? Top

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





PostPosted: Visual Basic for Applications (VBA), whats wrong with this code? Top

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

 
 
ChasAA





PostPosted: Visual Basic for Applications (VBA), whats wrong with this code? Top

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


 
 
magicalclick





PostPosted: Visual Basic for Applications (VBA), whats wrong with this code? Top

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


 
 
milkshake





PostPosted: Visual Basic for Applications (VBA), whats wrong with this code? Top

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



 
 
magicalclick





PostPosted: Visual Basic for Applications (VBA), whats wrong with this code? Top

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.