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

I am trying to do an if statement, involving a commission shedule,
with the following data, on VBA:

STOCK PRICE COMMISSION
$0 - $.24 2.5%
$.25 - $1 $35 + $.005 per share
$1.01 - $2 $35 + $.02 per share
$2.01 - $5 $35 + $.03 per share
$5.01 - $10 $35 + $.04 per share
$10.01- $20 $35 + $.05 per share
$20.01 and over $35 + $.06 per share

I have set up the cells on my spread sheet as follows:

A1 = quantity (no. of shares)
A2 = price
A3 = contains the answer / commission.

Sub Commission()
If [a2] 0 And [a2] <= 0.24 Then
[a3] = [a1] * [a2] * 0.025
ElseIf [a2] = 0.25 And [a2] <= 1 Then
[a3] = [a1] * 0.005 + 35
ElseIf [a2] = 1.01 And [a2] <= 2 Then
[a3] = [a1] * 0.02 + 35
ElseIf [a2] = 2.01 And [a2] <= 5 Then
[c1] = [a1] * 0.03 + 35
ElseIf [a2] = 5.01 And [a2] <= 10 Then
[c1] = [a1] * 0.04 + 35
ElseIf [a2] = 10.01 And [a2] <= 20 Then
[c1] = [a1] * 0.05 + 35
ElseIf [a2] = 20.01 Then
[c1] = [a1] * 0.06 + 35
Else: [c1] = ""

End Sub

I have manually typed the above exactly as shown (nothing else)
however it does not work. When for example I have cell A1 = 500;
A2 = 5.25; instead of cell A3 showing the answer $55. it is blank?

Your help in this mater is greatly appreciated.

Susan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default If Statement

You didn't have an end if
You changed to C1 about half way through your routine.

Sub Commission()
If [a2] 0 And [a2] <= 0.24 Then
[a3] = [a1] * [a2] * 0.025
ElseIf [a2] = 0.25 And [a2] <= 1 Then
[a3] = [a1] * 0.005 + 35
ElseIf [a2] = 1.01 And [a2] <= 2 Then
[a3] = [a1] * 0.02 + 35
ElseIf [a2] = 2.01 And [a2] <= 5 Then
[a3] = [a1] * 0.03 + 35
ElseIf [a2] = 5.01 And [a2] <= 10 Then
[a3] = [a1] * 0.04 + 35
ElseIf [a2] = 10.01 And [a2] <= 20 Then
[a3] = [a1] * 0.05 + 35
ElseIf [a2] = 20.01 Then
[a3] = [a1] * 0.06 + 35
Else
[a3] = ""
End If
End Sub

--
Regards,
Tom Ogilvy

<Susan Hayes wrote in message
...
I am trying to do an if statement, involving a commission shedule,
with the following data, on VBA:

STOCK PRICE COMMISSION
$0 - $.24 2.5%
$.25 - $1 $35 + $.005 per share
$1.01 - $2 $35 + $.02 per share
$2.01 - $5 $35 + $.03 per share
$5.01 - $10 $35 + $.04 per share
$10.01- $20 $35 + $.05 per share
$20.01 and over $35 + $.06 per share

I have set up the cells on my spread sheet as follows:

A1 = quantity (no. of shares)
A2 = price
A3 = contains the answer / commission.

Sub Commission()
If [a2] 0 And [a2] <= 0.24 Then
[a3] = [a1] * [a2] * 0.025
ElseIf [a2] = 0.25 And [a2] <= 1 Then
[a3] = [a1] * 0.005 + 35
ElseIf [a2] = 1.01 And [a2] <= 2 Then
[a3] = [a1] * 0.02 + 35
ElseIf [a2] = 2.01 And [a2] <= 5 Then
[c1] = [a1] * 0.03 + 35
ElseIf [a2] = 5.01 And [a2] <= 10 Then
[c1] = [a1] * 0.04 + 35
ElseIf [a2] = 10.01 And [a2] <= 20 Then
[c1] = [a1] * 0.05 + 35
ElseIf [a2] = 20.01 Then
[c1] = [a1] * 0.06 + 35
Else: [c1] = ""

End Sub

I have manually typed the above exactly as shown (nothing else)
however it does not work. When for example I have cell A1 = 500;
A2 = 5.25; instead of cell A3 showing the answer $55. it is blank?

Your help in this mater is greatly appreciated.

Susan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default If Statement

It appears that afew C1's have found their way into your code...

ElseIf [a2] = 2.01 And [a2] <= 5 Then
[c1] = [a1] * 0.03 + 35
ElseIf [a2] = 5.01 And [a2] <= 10 Then
[c1] = [a1] * 0.04 + 35
ElseIf [a2] = 10.01 And [a2] <= 20 Then
[c1] = [a1] * 0.05 + 35
ElseIf [a2] = 20.01 Then
[c1] = [a1] * 0.06 + 35
Else: [c1] = ""

Could that be where it's going wrong?


<Susan Hayes wrote in message
...
I am trying to do an if statement, involving a commission shedule,
with the following data, on VBA:

STOCK PRICE COMMISSION
$0 - $.24 2.5%
$.25 - $1 $35 + $.005 per share
$1.01 - $2 $35 + $.02 per share
$2.01 - $5 $35 + $.03 per share
$5.01 - $10 $35 + $.04 per share
$10.01- $20 $35 + $.05 per share
$20.01 and over $35 + $.06 per share

I have set up the cells on my spread sheet as follows:

A1 = quantity (no. of shares)
A2 = price
A3 = contains the answer / commission.

Sub Commission()
If [a2] 0 And [a2] <= 0.24 Then
[a3] = [a1] * [a2] * 0.025
ElseIf [a2] = 0.25 And [a2] <= 1 Then
[a3] = [a1] * 0.005 + 35
ElseIf [a2] = 1.01 And [a2] <= 2 Then
[a3] = [a1] * 0.02 + 35
ElseIf [a2] = 2.01 And [a2] <= 5 Then
[c1] = [a1] * 0.03 + 35
ElseIf [a2] = 5.01 And [a2] <= 10 Then
[c1] = [a1] * 0.04 + 35
ElseIf [a2] = 10.01 And [a2] <= 20 Then
[c1] = [a1] * 0.05 + 35
ElseIf [a2] = 20.01 Then
[c1] = [a1] * 0.06 + 35
Else: [c1] = ""

End Sub

I have manually typed the above exactly as shown (nothing else)
however it does not work. When for example I have cell A1 = 500;
A2 = 5.25; instead of cell A3 showing the answer $55. it is blank?

Your help in this mater is greatly appreciated.

Susan



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 statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Embedding an OR statement in an IF statement efficiently Chatnoir11 Excel Discussion (Misc queries) 4 February 2nd 09 08:12 PM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM
If statement and Isblank statement Rodney C. Excel Worksheet Functions 0 January 18th 05 08:39 PM


All times are GMT +1. The time now is 07:00 PM.

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"