Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default If Statments

I have a code the based on the user input of tr and rn will determine
the value of bn.
I tried to structure it as you see below but it does not pass bn on to
when it needs to be used.

Any help would be appreciated.



tr, bn and rn are declard as long


tr = InputBox("TOTAL BOXES IN THIS ORDERB.")
rn = InputBox("THIS IS BOX NUMBER?")


If tr = 4 Then

ElseIf rn = 4 Then bn = 1
ElseIf rn = 3 Then bn = 2
ElseIf rn = 2 Then bn = 3
ElseIf rn = 1 Then bn = 4



End If


If tr = 3 Then


ElseIf rn = 3 Then bn = 1
ElseIf rn = 2 Then bn = 2
ElseIf rn = 1 Then bn = 3



End If




If tr = 2 Then


ElseIf rn = 2 Then bn = 1
ElseIf rn = 1 Then bn = 2



End If




Thanks



Little Penny
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default If Statments

Hi Little Penny.
Invalid use of ElseIf, I believe.

Try:

If tr = 4 And rn = 4 Then bn = 1
If tr = 4 And rn = 3 Then bn = 2
If tr = 4 And rn = 2 Then bn = 3
If tr = 4 And rn = 1 Then bn = 4

and so on.

Buon Natale
Eliano


On 23 Dic, 00:26, Little Penny wrote:
I have a code the based on the user input of tr and rn will determine
the value of bn.
I tried to structure it as you see below but it does not pass bn on to
when it needs to be used.

Any help would be appreciated.

tr, bn and rn are declard as long

tr = InputBox("TOTAL BOXES IN THIS ORDERB.")
rn = InputBox("THIS IS BOX NUMBER?")

If tr = 4 Then

* * ElseIf rn = 4 Then bn = 1
* * ElseIf rn = 3 Then bn = 2
* * ElseIf rn = 2 Then bn = 3
* * ElseIf rn = 1 Then bn = 4

End If

If tr = 3 Then

* * ElseIf rn = 3 Then bn = 1
* * ElseIf rn = 2 Then bn = 2
* * ElseIf rn = 1 Then bn = 3

End If

If tr = 2 Then

* * ElseIf rn = 2 Then bn = 1
* * ElseIf rn = 1 Then bn = 2

End If

Thanks

Little Penny


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default If Statments


Or:

If tr = 4 Then
If rn = 4 Then
bn = 1
ElseIf rn = 3 Then
bn = 2
ElseIf rn = 2 Then
bn = 3
ElseIf rn = 1 Then
bn = 4
End If
End If

When you use the ElseIf statement you have to follow the block fromat. That
means the If...then has to be on a separate line than the executable
statement and the ElseIf...Then has to be on a separate line than the
executable statment and the End If has to be on a separate line. In your
case, you wanted to use a nested If...Then...ElseIf...Then inside an
If...Then.

If...Then 'If the first condition us met
If...Then 'Then check for different condition, etc.
'do something
ElseIf...Then
'do something
End If
End If


"Little Penny" wrote:

I have a code the based on the user input of tr and rn will determine
the value of bn.
I tried to structure it as you see below but it does not pass bn on to
when it needs to be used.

Any help would be appreciated.



tr, bn and rn are declard as long


tr = InputBox("TOTAL BOXES IN THIS ORDERB.")
rn = InputBox("THIS IS BOX NUMBER?")


If tr = 4 Then

ElseIf rn = 4 Then bn = 1
ElseIf rn = 3 Then bn = 2
ElseIf rn = 2 Then bn = 3
ElseIf rn = 1 Then bn = 4



End If


If tr = 3 Then


ElseIf rn = 3 Then bn = 1
ElseIf rn = 2 Then bn = 2
ElseIf rn = 1 Then bn = 3



End If




If tr = 2 Then


ElseIf rn = 2 Then bn = 1
ElseIf rn = 1 Then bn = 2



End If




Thanks



Little Penny

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default If Statments

You may want to try the select case structu

Select case tr
case is = 4
select case rn
case is = 4:bn=1
case is = 4:bn=1
case is = 4:bn=1


Little Penny wrote:

I have a code the based on the user input of tr and rn will determine
the value of bn.
I tried to structure it as you see below but it does not pass bn on to
when it needs to be used.

Any help would be appreciated.

tr, bn and rn are declard as long

tr = InputBox("TOTAL BOXES IN THIS ORDERB.")
rn = InputBox("THIS IS BOX NUMBER?")

If tr = 4 Then

ElseIf rn = 4 Then bn = 1
ElseIf rn = 3 Then bn = 2
ElseIf rn = 2 Then bn = 3
ElseIf rn = 1 Then bn = 4



End If

If tr = 3 Then


ElseIf rn = 3 Then bn = 1
ElseIf rn = 2 Then bn = 2
ElseIf rn = 1 Then bn = 3



End If

If tr = 2 Then


ElseIf rn = 2 Then bn = 1
ElseIf rn = 1 Then bn = 2



End If

Thanks

Little Penny


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default If Statments

Stupid fingers!

You may want to try the select case structu

Select case tr
case is = 4
select case rn
case is = 4:bn=1
case is = 3:bn=2
case is = 2:bn=3
case is = 1:bn=4
end select
case is = 8888 '
select case rn 'do more tests here
case is = 4:bn=1
case is = 3:bn=2
case is = 2:bn=3
case is = 1:bn=4
end select
end select

======
But sometimes, you can use math:

if tr = 4 then
bn = 5 - rn
else...


Little Penny wrote:

I have a code the based on the user input of tr and rn will determine
the value of bn.
I tried to structure it as you see below but it does not pass bn on to
when it needs to be used.

Any help would be appreciated.

tr, bn and rn are declard as long

tr = InputBox("TOTAL BOXES IN THIS ORDERB.")
rn = InputBox("THIS IS BOX NUMBER?")

If tr = 4 Then

ElseIf rn = 4 Then bn = 1
ElseIf rn = 3 Then bn = 2
ElseIf rn = 2 Then bn = 3
ElseIf rn = 1 Then bn = 4



End If

If tr = 3 Then


ElseIf rn = 3 Then bn = 1
ElseIf rn = 2 Then bn = 2
ElseIf rn = 1 Then bn = 3



End If

If tr = 2 Then


ElseIf rn = 2 Then bn = 1
ElseIf rn = 1 Then bn = 2



End If

Thanks

Little Penny


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default If Statments

I am pretty sure that this code can replace all the code that you posted...

tr = InputBox("TOTAL BOXES IN THIS ORDERB.")
rn = InputBox("THIS IS BOX NUMBER?")
bn = 1 + tr - rn

--
Rick (MVP - Excel)


"Little Penny" wrote in message
...
I have a code the based on the user input of tr and rn will determine
the value of bn.
I tried to structure it as you see below but it does not pass bn on to
when it needs to be used.

Any help would be appreciated.



tr, bn and rn are declard as long


tr = InputBox("TOTAL BOXES IN THIS ORDERB.")
rn = InputBox("THIS IS BOX NUMBER?")


If tr = 4 Then

ElseIf rn = 4 Then bn = 1
ElseIf rn = 3 Then bn = 2
ElseIf rn = 2 Then bn = 3
ElseIf rn = 1 Then bn = 4



End If


If tr = 3 Then


ElseIf rn = 3 Then bn = 1
ElseIf rn = 2 Then bn = 2
ElseIf rn = 1 Then bn = 3



End If




If tr = 2 Then


ElseIf rn = 2 Then bn = 1
ElseIf rn = 1 Then bn = 2



End If




Thanks



Little Penny


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
If then Statments Tina Excel Worksheet Functions 5 January 20th 09 09:43 PM
IF Statments with VLOOKUP Ultrasayjin Excel Discussion (Misc queries) 3 December 19th 08 08:58 PM
If statments Lweiss Excel Worksheet Functions 2 March 20th 08 08:01 AM
If Statments Jason Excel Discussion (Misc queries) 2 January 3rd 08 05:33 PM
AND OR IF Statments Rogie Excel Worksheet Functions 3 February 12th 07 04:01 AM


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

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

About Us

"It's about Microsoft Excel"