View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
meiftan meiftan is offline
external usenet poster
 
Posts: 6
Default if statement in an if statement

thank you for your reply,

the code works only if the user checks all the checkboxes, when there is a
checkbox not checked, example

checkbox1 checked
checkbox2 not checked
checkbox3 checked

the code won't run the 'something'
I need something like this

If Userform1.Checkbox1.Value = True (AND this condition
Userform1.Checkbox2=True<<If the value is True) And

Userform1.Checkbox3.Value = True Then
Run something

So, based on example, the code will only run like this

If Userform1.Checkbox1.Value = True And Userform1.Checkbox3.Value = True Then
Run something
End If

If I have to make codes for the all possible user's check/s, then I have to
make 7 different codes like this

If Userfom1.Checkbox1.Value = True Then
Run something
End If

If Userfom1.Checkbox1.Value = True And Userfom1.Checkbox2.Value = True Then
Run something
End If

If Userfom1.Checkbox1.Value = True And Userfom1.Checkbox3.Value = True Then
Run something
End If

If Userfom1.Checkbox2.Value = True Then
Run something
End If

If Userfom1.Checkbox2.Value = True And Userfom1.Checkbox3.Value = True Then
Run something
End If

If Userfom1.Checkbox3.Value = True Then
Run something
End If

If Userfom1.Checkbox1.Value = True And Userfom1.Checkbox2.Value = True And
Userfom1.Checkbox3.Value = True Then
Run something
End If

the codes need to be simplified

Best Regards,

"JMB" wrote:

This code that you posted works fine for me

If Userform1.Checkbox1.Value = True And Userform1.Checkbox2.Value = True And
Userform1.Checkbox3.Value = True Then
Run something


Are you sure you are referencing the correct checkbox control??



"meiftan" wrote:

Dears,
I have a trouble in using if statement in macro, hope someone with
"Excel"ent mind answer my question, sorry for my bad English.

Here's the macro in my mind,

If Userform1.Checkbox1.Value = True (If "AND" Userform1.Checkbox2.Value =
True(If "AND" Userform1.Checkbox3.Value)) Then
Run something

I used this before,

If Userform1.Checkbox1.Value = True And Userform1.Checkbox2.Value = True And
Userform1.Checkbox3.Value = True Then
Run something

But when the Checkbox2.Value = False , It doesn't work , I changed AND to
OR, same result, the point is when the value = False, then non-activate that
condition.

Regards,