#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Select Case

I am trying to us a Select Case Construction but I am not able to get the
program to choose the branch.

I have a spreadsheet similar to the following:
A B C D
E
1 Old
2 Symbol Shares TotalShares
3 AMD 50
4
5 - New Trade -
6 Trade Type Symbol New Shares
7 ADD AMD 25
8

I want my code to put a value in cell below "TotalShares" (D3) based on the
entry in the cell below Trade Type (A7).

If the Trade Type is:
"ADD", add New Shares to Old Shares.
"SELLPARTIAL", subtract New Shares from Old Shares
"SELLALL", subtract New Shares from Old Shares and enter "sold" in E3

Here is my code.
My problem is that I want it to execute the statements below Case Add but it
skips over that code. I don't know how to indicate that this is Case ADD.

How to I fix this? Thanks, Alan


Sub ProcessTrades()

Dim TrType As Range
Dim OldShares As Range
Dim TradeShares As Range
Dim TotalShares As Range

Set OldShares = Range("C3")
Set TradeShares = Range("C7")
Set TotalShares = Range("D3")
Set TrType = Range("A7")

Select Case TrType

Case Add
TotalShares.Value = OldShares.Value + TradeShares.Value

Case SellPartial
TotalShares.Value = OldShares.Value - TradeShares.Value

Case SellAll
TotalShares.Value = OldShares.Value - TradeShares.Value
Range(E3).Value = "sold"

End Select
End Sub


achidsey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Select Case

try this automatic idea which is accomplished by what you type in col a.
Modify to suit.

right click sheet tabview codeinsert thismodify to suitsave

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 1 Then Exit Sub
Select Case Target
Case "a": Target.Offset(0, 1) = Target.Offset(0, 2) - Target.Offset(0, 3)
case "buy"
case "sell"
End Select
Cancel = True
End Sub

--
Don Guillett
SalesAid Software

"achidsey" (notmorespam) wrote in message
...
I am trying to us a Select Case Construction but I am not able to get the
program to choose the branch.

I have a spreadsheet similar to the following:
A B C D
E
1 Old
2 Symbol Shares TotalShares
3 AMD 50
4
5 - New Trade -
6 Trade Type Symbol New Shares
7 ADD AMD 25
8

I want my code to put a value in cell below "TotalShares" (D3) based on

the
entry in the cell below Trade Type (A7).

If the Trade Type is:
"ADD", add New Shares to Old Shares.
"SELLPARTIAL", subtract New Shares from Old Shares
"SELLALL", subtract New Shares from Old Shares and enter "sold" in

E3

Here is my code.
My problem is that I want it to execute the statements below Case Add but

it
skips over that code. I don't know how to indicate that this is Case ADD.

How to I fix this? Thanks, Alan


Sub ProcessTrades()

Dim TrType As Range
Dim OldShares As Range
Dim TradeShares As Range
Dim TotalShares As Range

Set OldShares = Range("C3")
Set TradeShares = Range("C7")
Set TotalShares = Range("D3")
Set TrType = Range("A7")

Select Case TrType

Case Add
TotalShares.Value = OldShares.Value + TradeShares.Value

Case SellPartial
TotalShares.Value = OldShares.Value - TradeShares.Value

Case SellAll
TotalShares.Value = OldShares.Value - TradeShares.Value
Range(E3).Value = "sold"

End Select
End Sub


achidsey



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Select Case

Try
case "Add" etc

Wolf

"achidsey" wrote:

I am trying to us a Select Case Construction but I am not able to get the
program to choose the branch.

I have a spreadsheet similar to the following:
A B C D
E
1 Old
2 Symbol Shares TotalShares
3 AMD 50
4
5 - New Trade -
6 Trade Type Symbol New Shares
7 ADD AMD 25
8

I want my code to put a value in cell below "TotalShares" (D3) based on the
entry in the cell below Trade Type (A7).

If the Trade Type is:
"ADD", add New Shares to Old Shares.
"SELLPARTIAL", subtract New Shares from Old Shares
"SELLALL", subtract New Shares from Old Shares and enter "sold" in E3

Here is my code.
My problem is that I want it to execute the statements below Case Add but it
skips over that code. I don't know how to indicate that this is Case ADD.

How to I fix this? Thanks, Alan


Sub ProcessTrades()

Dim TrType As Range
Dim OldShares As Range
Dim TradeShares As Range
Dim TotalShares As Range

Set OldShares = Range("C3")
Set TradeShares = Range("C7")
Set TotalShares = Range("D3")
Set TrType = Range("A7")

Select Case TrType

Case Add
TotalShares.Value = OldShares.Value + TradeShares.Value

Case SellPartial
TotalShares.Value = OldShares.Value - TradeShares.Value

Case SellAll
TotalShares.Value = OldShares.Value - TradeShares.Value
Range(E3).Value = "sold"

End Select
End Sub


achidsey

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Select Case

Thank you. That worked.
--
achidsey


"Wolf" wrote:

Try
case "Add" etc

Wolf

"achidsey" wrote:

I am trying to us a Select Case Construction but I am not able to get the
program to choose the branch.

I have a spreadsheet similar to the following:
A B C D
E
1 Old
2 Symbol Shares TotalShares
3 AMD 50
4
5 - New Trade -
6 Trade Type Symbol New Shares
7 ADD AMD 25
8

I want my code to put a value in cell below "TotalShares" (D3) based on the
entry in the cell below Trade Type (A7).

If the Trade Type is:
"ADD", add New Shares to Old Shares.
"SELLPARTIAL", subtract New Shares from Old Shares
"SELLALL", subtract New Shares from Old Shares and enter "sold" in E3

Here is my code.
My problem is that I want it to execute the statements below Case Add but it
skips over that code. I don't know how to indicate that this is Case ADD.

How to I fix this? Thanks, Alan


Sub ProcessTrades()

Dim TrType As Range
Dim OldShares As Range
Dim TradeShares As Range
Dim TotalShares As Range

Set OldShares = Range("C3")
Set TradeShares = Range("C7")
Set TotalShares = Range("D3")
Set TrType = Range("A7")

Select Case TrType

Case Add
TotalShares.Value = OldShares.Value + TradeShares.Value

Case SellPartial
TotalShares.Value = OldShares.Value - TradeShares.Value

Case SellAll
TotalShares.Value = OldShares.Value - TradeShares.Value
Range(E3).Value = "sold"

End Select
End Sub


achidsey

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default Select Case

or this

Sub ProcessTrades()

Dim TrType As Range
Dim OldShares As Range
Dim TradeShares As Range
Dim TotalShares As Range

Set OldShares = Range("C3")
Set TradeShares = Range("C7")
Set TotalShares = Range("D3")
Set TrType = Range("A7")

If TrType = "Add" Then
TotalShares = OldShares + TradeShares
End If

If TrType = "SellPartial" Then
TotalShares = OldShares - TradeShares
End If

If TrType = "SellAll" Then
TotalShares = OldShares - TradeShares
Range("E3").Value = "sold"

End If
End Sub

--


Gary


"achidsey" (notmorespam) wrote in message
...
Thank you. That worked.
--
achidsey


"Wolf" wrote:

Try
case "Add" etc

Wolf

"achidsey" wrote:

I am trying to us a Select Case Construction but I am not able to get
the
program to choose the branch.

I have a spreadsheet similar to the following:
A B C D
E
1 Old
2 Symbol Shares TotalShares
3 AMD 50
4
5 - New Trade -
6 Trade Type Symbol New Shares
7 ADD AMD 25
8

I want my code to put a value in cell below "TotalShares" (D3) based on
the
entry in the cell below Trade Type (A7).

If the Trade Type is:
"ADD", add New Shares to Old Shares.
"SELLPARTIAL", subtract New Shares from Old Shares
"SELLALL", subtract New Shares from Old Shares and enter "sold"
in E3

Here is my code.
My problem is that I want it to execute the statements below Case Add
but it
skips over that code. I don't know how to indicate that this is Case
ADD.

How to I fix this? Thanks, Alan


Sub ProcessTrades()

Dim TrType As Range
Dim OldShares As Range
Dim TradeShares As Range
Dim TotalShares As Range

Set OldShares = Range("C3")
Set TradeShares = Range("C7")
Set TotalShares = Range("D3")
Set TrType = Range("A7")

Select Case TrType

Case Add
TotalShares.Value = OldShares.Value + TradeShares.Value

Case SellPartial
TotalShares.Value = OldShares.Value - TradeShares.Value

Case SellAll
TotalShares.Value = OldShares.Value - TradeShares.Value
Range(E3).Value = "sold"

End Select
End Sub


achidsey



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
select case Hein Excel Discussion (Misc queries) 5 November 24th 09 01:19 PM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
Select Case Jeff Excel Discussion (Misc queries) 1 February 27th 06 02:56 PM
Case Select Kelly Excel Programming 6 March 16th 05 01:29 PM
For Each with Select Case helmekki[_28_] Excel Programming 2 October 15th 04 03:23 AM


All times are GMT +1. The time now is 11:29 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"