VBA for summing buys and sells

H

Helixal

I created the following simplistic macro to change the signs of numbers in
cols 4 and 7 according to whether column 3 contained a buy, sell etc. See
speradsheet below.

the following formulas in cols H and I row 2 and copied down:

H=D2+SUMIF($B$1:B1,B2,$D$1:D1)


I=G2+SUMIF($B$1:B1,B2,$G$1:G1)

work to sum columns 4 and 7 up to the point where the name changes in
collumn 2. As can be seen in the spreadsheet below.

I'd like some help in incorporating the two formulas into the macro.




Sub changesign2()

x = 2
Do While Cells(x, 3).Value <> ""

If (Cells(x, 3).Value Like "*Rem*") Then
Cells(x, 4).Value = -Abs(Cells(x, 4))
Cells(x, 7).Value = Abs(Cells(x, 7))

ElseIf (Cells(x, 3).Value Like "*Sel*") Then
Cells(x, 4).Value = -Abs(Cells(x, 4))
Cells(x, 7).Value = Abs(Cells(x, 7))

ElseIf (Cells(x, 3).Value Like "*Ret*") Then
Cells(x, 4).Value = -Abs(Cells(x, 4))
Cells(x, 7).Value = Abs(Cells(x, 7))

ElseIf (Cells(x, 3).Value Like "*Add*") Then
Cells(x, 4).Value = Abs(Cells(x, 4))
Cells(x, 7).Value = -Abs(Cells(x, 7))

ElseIf (Cells(x, 3).Value Like "*Buy*") Then
Cells(x, 4).Value = Abs(Cells(x, 4))
Cells(x, 7).Value = -Abs(Cells(x, 7))


Else
Cells(x, 4).Value = Abs(Cells(x, 4))
Cells(x, 7).Value = Abs(Cells(x, 7))
End If


x = x + 1
Loop

End sub
####################################################################################3

DATE NAME ACTIVITY QUANTITY PRICE COMMIS TOTAL net
quant net tot
date1 name1 Buy 34 0 2.36 -99 34 -99
date2 name1 Sell -24 0 2.36 56 10 -43
date3 name2 Buy 56 0 2.36 -99 56 -99
date4 name2 Buy 36 0 2.36 -103 92 -202
date4a name2 Sell -92 0 2.36 504 0 302
date5 name3 Add Shares 28 0 2.36 -34 28 -34
date6 name3 Remem. Shares -12 0 2.36 470 16 436
date7 name3 Buy 10 0 2.36 -36 26 400
date8 name3 Rem. Shares -15 0 2.36 99 11 499
date9 name3 Add Shares 75 0 2.36 -85 86 414
date9 name3 Ret.Cap -23 0 2.36 98 63 512
date9 name3 RtRet -45 0 2.36 36 18 548
date9 name3 Add Shares 75 0 2.36 -21 93 527


Thanks for your interest,

Al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top