Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default if statement in an if statement

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,
  #2   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default if statement in an if statement

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,

  #3   Report Post  
Posted to microsoft.public.excel.misc
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,

  #4   Report Post  
Posted to microsoft.public.excel.misc
TWR TWR is offline
external usenet poster
 
Posts: 30
Default if statement in an if statement

Try this:
Dim i as integer

i=0
With UserForm1
If .CheckBox1.value=true then i=i+1
If .CheckBox2.value=true then i=i+2
If .CheckBox3.value=true then i=i+4
End With

Select Case i
Case 0 ' No CB's Checked
Run Something
Case 1 ' Only CB1 Checked
Run Something
Case 2 ' Only CB2 Checked
Run Something
Case 3 ' CB's 1 & 2 Checked
Run Something
Case 4 ' Only CB 3 Checked
Run Something
Case 5 ' CB's 1 & 3 Checked
Run Something
Case 6 ' CB's 2 & 3 Checked
Run Something
Case 7 ' All CB's Checked
Run Something
End Select


"meiftan" wrote:

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,

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default if statement in an if statement

Really cool, Thank you for you help,

now I just make the code based on yours,
Actually there are 9 (nine!) checkboxes on my userform,
how many cases of possible user's check/s that I need to make?
There must be a lot of cases!

Once again, thank you so much for your help Mr.TWR

"TWR" wrote:

Try this:
Dim i as integer

i=0
With UserForm1
If .CheckBox1.value=true then i=i+1
If .CheckBox2.value=true then i=i+2
If .CheckBox3.value=true then i=i+4
End With

Select Case i
Case 0 ' No CB's Checked
Run Something
Case 1 ' Only CB1 Checked
Run Something
Case 2 ' Only CB2 Checked
Run Something
Case 3 ' CB's 1 & 2 Checked
Run Something
Case 4 ' Only CB 3 Checked
Run Something
Case 5 ' CB's 1 & 3 Checked
Run Something
Case 6 ' CB's 2 & 3 Checked
Run Something
Case 7 ' All CB's Checked
Run Something
End Select


"meiftan" wrote:

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,



  #6   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default if statement in an if statement

My apologies, I was not following your original question. I think you are
looking at 511 different combinations.


"meiftan" wrote:

Really cool, Thank you for you help,

now I just make the code based on yours,
Actually there are 9 (nine!) checkboxes on my userform,
how many cases of possible user's check/s that I need to make?
There must be a lot of cases!

Once again, thank you so much for your help Mr.TWR

"TWR" wrote:

Try this:
Dim i as integer

i=0
With UserForm1
If .CheckBox1.value=true then i=i+1
If .CheckBox2.value=true then i=i+2
If .CheckBox3.value=true then i=i+4
End With

Select Case i
Case 0 ' No CB's Checked
Run Something
Case 1 ' Only CB1 Checked
Run Something
Case 2 ' Only CB2 Checked
Run Something
Case 3 ' CB's 1 & 2 Checked
Run Something
Case 4 ' Only CB 3 Checked
Run Something
Case 5 ' CB's 1 & 3 Checked
Run Something
Case 6 ' CB's 2 & 3 Checked
Run Something
Case 7 ' All CB's Checked
Run Something
End Select


"meiftan" wrote:

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,

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default if statement in an if statement

dear all,

sorry for my late response
thank you for your calculation for the cases Mr. JMB
I think that if I had to make those 511 combination of codes,
then I wasted my time just for checking which checkbox/es is/are checked or
not ,
when the combination codes have been done,
there are another 511 combination of 'Run something' to be completed

Is this the best way to make a userform with alot of checkboxes for the user
to check some checkboxes and for us to identify which checkbox/es is/are
checked or not?

thanks all for the big idea,

warm regards,

"JMB" wrote:

My apologies, I was not following your original question. I think you are
looking at 511 different combinations.


"meiftan" wrote:

Really cool, Thank you for you help,

now I just make the code based on yours,
Actually there are 9 (nine!) checkboxes on my userform,
how many cases of possible user's check/s that I need to make?
There must be a lot of cases!

Once again, thank you so much for your help Mr.TWR

"TWR" wrote:

Try this:
Dim i as integer

i=0
With UserForm1
If .CheckBox1.value=true then i=i+1
If .CheckBox2.value=true then i=i+2
If .CheckBox3.value=true then i=i+4
End With

Select Case i
Case 0 ' No CB's Checked
Run Something
Case 1 ' Only CB1 Checked
Run Something
Case 2 ' Only CB2 Checked
Run Something
Case 3 ' CB's 1 & 2 Checked
Run Something
Case 4 ' Only CB 3 Checked
Run Something
Case 5 ' CB's 1 & 3 Checked
Run Something
Case 6 ' CB's 2 & 3 Checked
Run Something
Case 7 ' All CB's Checked
Run Something
End Select


"meiftan" wrote:

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,

  #8   Report Post  
Posted to microsoft.public.excel.misc
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default if statement in an if statement

I can't give an opinion on the "best" way to approach it as there are not
enough details of your project.

Generally, I would try to determine if any combinations can be eliminated
(ie - if Checkbox1 is checked, is it possible for Checkbox3 to be also be
checked). Also, are there any combinations that would result in the same
action being performed (are there actually 511 completely different actions
that will need to be taken depending on what checkboxes are checked?) Look
to see what can be combined.

Post some details to outline more specifically what you are working with and
what you are trying to accomplish. I or someone else may be able to assist.


"meiftan" wrote:

dear all,

sorry for my late response
thank you for your calculation for the cases Mr. JMB
I think that if I had to make those 511 combination of codes,
then I wasted my time just for checking which checkbox/es is/are checked or
not ,
when the combination codes have been done,
there are another 511 combination of 'Run something' to be completed

Is this the best way to make a userform with alot of checkboxes for the user
to check some checkboxes and for us to identify which checkbox/es is/are
checked or not?

thanks all for the big idea,

warm regards,

"JMB" wrote:

My apologies, I was not following your original question. I think you are
looking at 511 different combinations.


"meiftan" wrote:

Really cool, Thank you for you help,

now I just make the code based on yours,
Actually there are 9 (nine!) checkboxes on my userform,
how many cases of possible user's check/s that I need to make?
There must be a lot of cases!

Once again, thank you so much for your help Mr.TWR

"TWR" wrote:

Try this:
Dim i as integer

i=0
With UserForm1
If .CheckBox1.value=true then i=i+1
If .CheckBox2.value=true then i=i+2
If .CheckBox3.value=true then i=i+4
End With

Select Case i
Case 0 ' No CB's Checked
Run Something
Case 1 ' Only CB1 Checked
Run Something
Case 2 ' Only CB2 Checked
Run Something
Case 3 ' CB's 1 & 2 Checked
Run Something
Case 4 ' Only CB 3 Checked
Run Something
Case 5 ' CB's 1 & 3 Checked
Run Something
Case 6 ' CB's 2 & 3 Checked
Run Something
Case 7 ' All CB's Checked
Run Something
End Select


"meiftan" wrote:

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,

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can an If statement answer an If statement? M.A.Tyler Excel Discussion (Misc queries) 2 June 24th 07 04:14 AM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM
if statement pwoodix Excel Worksheet Functions 3 August 16th 05 12:40 PM
If statement and Isblank statement Rodney C. Excel Worksheet Functions 0 January 18th 05 08:39 PM
Help please, IF statement/SUMIF statement Brad_A Excel Worksheet Functions 23 January 11th 05 02:24 PM


All times are GMT +1. The time now is 08:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"