ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Why doesn't this work (https://www.excelbanter.com/excel-programming/338211-why-doesnt-work.html)

Nicole D.

Why doesn't this work
 
I created a form in excel and when the user clicks on a checkbox I want
option button to default to true or false. I wrote the following statement:

Private Sub chkQAuto_Click()

If chkQAuto.Value = False Then
optDe3.Value = True And optAsir3.Value = True
'Else: optDe3.Value = False And optAsir3.Value = False
End If

End Sub

Can someone tell me why it doesn't work?

~Nicole

Chip Pearson

Why doesn't this work
 
Nicole,

You are misusing the AND keyword.

optDe3.Value = True And optAsir3.Value = True
should be
optDe3.Value = True
optAsir3.Value = True


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Nicole D." wrote in message
...
I created a form in excel and when the user clicks on a checkbox
I want
option button to default to true or false. I wrote the
following statement:

Private Sub chkQAuto_Click()

If chkQAuto.Value = False Then
optDe3.Value = True And optAsir3.Value = True
'Else: optDe3.Value = False And optAsir3.Value = False
End If

End Sub

Can someone tell me why it doesn't work?

~Nicole




crazybass2

Why doesn't this work
 
Private Sub chkQAuto_Click()

If chkQAuto.Value = False Then
optAsir3.Value = True
optDe3.Value = True
Else
optDe3.Value = False
optAsir3.Value = False
End If
End Sub


"Chip Pearson" wrote:

Nicole,

You are misusing the AND keyword.

optDe3.Value = True And optAsir3.Value = True
should be
optDe3.Value = True
optAsir3.Value = True


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Nicole D." wrote in message
...
I created a form in excel and when the user clicks on a checkbox
I want
option button to default to true or false. I wrote the
following statement:

Private Sub chkQAuto_Click()

If chkQAuto.Value = False Then
optDe3.Value = True And optAsir3.Value = True
'Else: optDe3.Value = False And optAsir3.Value = False
End If

End Sub

Can someone tell me why it doesn't work?

~Nicole





Jake Marx[_3_]

Why doesn't this work
 
Hi Nicole,

As Chip pointed out, you can't execute two separate statements with the And
operator. You could use the colon (":"), but I personally don't use those
much in my code.

A quicker way to do what you're trying to do is this:

optDe3.Value = Not chkQAuto.Value
optAsir3.Value = Not chkQAuto.Value

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Nicole D. wrote:
I created a form in excel and when the user clicks on a checkbox I
want option button to default to true or false. I wrote the following
statement:

Private Sub chkQAuto_Click()

If chkQAuto.Value = False Then
optDe3.Value = True And optAsir3.Value = True
'Else: optDe3.Value = False And optAsir3.Value = False
End If

End Sub

Can someone tell me why it doesn't work?

~Nicole




All times are GMT +1. The time now is 02:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com