467,076 Members | 891 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,076 developers. It's quick & easy.

Assigning values and summing results into specific cell

Thank you in advance for the help. I'm using Microsoft XP, I'm in the VBA editor in Excel. I'm trying to write code that will assign a positive or negative value based upon what the adjacent cell reads. Example:

Buy 70
Sell 45
Sell 30
Sell 25
Buy 65

My goal is to have code that will assign negative values to 'Sell' values and positive values to 'Buy" values. Additionally, I would like to have the net result posted into a specific cell. I'm very new to this, please let me know if you need more information.
Jul 25 '08 #1
  • viewed: 1714
1 Reply
Expert 8TB
If you are only going to have a limited amount of data, and your only options will be either Sell or Buy, you can set the Formulas in the individual Cells. If Column A contains only Sell or Buy, and Column B will contain the numeric values:
Expand|Select|Wrap|Line Numbers
  1. =IF(A1="Sell",45,-45)          'place in Cell(B1)
For simple summarizing, use the Sum() Function. The following Formula placed in any Cell will Sum the values from B1 to B25 inclusive:
Expand|Select|Wrap|Line Numbers
  1. =SUM(B1:B25)
Jul 26 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Yaroslav Bulatov | last post: by
2 posts views Thread by Jim Gregg | last post: by
reply views Thread by John Wright | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.