shutterback
New Member
- Joined
- Sep 15, 2017
- Messages
- 3
I have a dataset that looks like this for 1400 rows:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Buy[/TD]
[TD]273[/TD]
[/TR]
[TR]
[TD]Buy[/TD]
[TD]263[/TD]
[/TR]
[TR]
[TD]Sell_short[/TD]
[TD]340[/TD]
[/TR]
[TR]
[TD]Sell_long[/TD]
[TD]209[/TD]
[/TR]
[TR]
[TD]Buy[/TD]
[TD]271[/TD]
[/TR]
</tbody>[/TABLE]
When the left column is buy, the right column gets added to the account. When the left column is sell_short or sell_long, the right column gets detracted from the account. When the left column is sell_long, the counter after selling should be a positive number, and when the left column says sell_short, the counter after selling should be a negative number. I want to run a for loop through all of the rows, adding to the counter when left is buy and detracting when left is sell, and if the counter is negative but the left column says long, highlight the cell in red. If the counter is positive and the left column says short, highlight the cell in red. Otherwise, do nothing.
So far, I have
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #fffb00}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #ffffff ; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #ffffff }p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993 ; background-color: #ffffff }span.s1 {color: #011993 }span.s2 {color: #000000 }</style>Sub counter()
Dim x As Range
Dim counter As Integer
counter = 0
For Each x In Range("D2", Range("D" & Rows.Count).End(xlUp))
If x.Offset(0, -1) = "Buy" Then
counter = counter + x
ElseIf x.Offset(0, -1).Value Like "*Sell*" Then
counter = counter - x
End If
Next x
End Sub
Need advice for where to go from here!
[TABLE="width: 500"]
<tbody>[TR]
[TD]Buy[/TD]
[TD]273[/TD]
[/TR]
[TR]
[TD]Buy[/TD]
[TD]263[/TD]
[/TR]
[TR]
[TD]Sell_short[/TD]
[TD]340[/TD]
[/TR]
[TR]
[TD]Sell_long[/TD]
[TD]209[/TD]
[/TR]
[TR]
[TD]Buy[/TD]
[TD]271[/TD]
[/TR]
</tbody>[/TABLE]
When the left column is buy, the right column gets added to the account. When the left column is sell_short or sell_long, the right column gets detracted from the account. When the left column is sell_long, the counter after selling should be a positive number, and when the left column says sell_short, the counter after selling should be a negative number. I want to run a for loop through all of the rows, adding to the counter when left is buy and detracting when left is sell, and if the counter is negative but the left column says long, highlight the cell in red. If the counter is positive and the left column says short, highlight the cell in red. Otherwise, do nothing.
So far, I have
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #fffb00}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #ffffff ; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #ffffff }p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993 ; background-color: #ffffff }span.s1 {color: #011993 }span.s2 {color: #000000 }</style>Sub counter()
Dim x As Range
Dim counter As Integer
counter = 0
For Each x In Range("D2", Range("D" & Rows.Count).End(xlUp))
If x.Offset(0, -1) = "Buy" Then
counter = counter + x
ElseIf x.Offset(0, -1).Value Like "*Sell*" Then
counter = counter - x
End If
Next x
End Sub
Need advice for where to go from here!