By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

Assigning values and summing results into specific cell

P: 1
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
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,638
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.