Hi
I am struggling with a part of a project I am working on and have been unable to find a solution. Hoping someone here can assist.
I need to be able to insert formulas into columns AA-AG, based on data (that is variable) in column H
I am calculating capital gains based on tax lots and the formulas are specific to that. There could be one tax lot per security or many. The first row of formula would need to correspond with the change in value (tickers) in column H. The second line would then be copied down for the remaining rows, until the value in col H changes.
<tbody>
[TD="colspan: 2"]AC
[/TD]
[TD="colspan: 2"]=IF(AA4>0,(J4-AA4)/J4*P4,0)
[/TD]
[TD="colspan: 2"]=IF(AA5>0,(J5-AA5)/J5*P5,0)
[/TD]
[TD="colspan: 2"]=IF(AA6>0,(J6-AA6)/J6*P6,0)
[/TD]
[TD="colspan: 2"]=IF(AA4>0,(J4-AA4)/J4*P4,0)
[/TD]
[TD="colspan: 2"]=IF(AA5>0,(J5-AA5)/J5*P5,0)
[/TD]
[TD="colspan: 2"]=IF(AA6>0,(J6-AA6)/J6*P6,0)
[/TD]
[TD="colspan: 2"]=IF(AA5>0,(J5-AA5)/J5*P5,0)
[/TD]
[TD="colspan: 2"]=IF(AA6>0,(J6-AA6)/J6*P6,0)
[/TD]
[TD="colspan: 2"]=IF(AA6>0,(J6-AA6)/J6*P6,0)
[/TD]
[TD="colspan: 2"]=IF(AA4>0,(J4-AA4)/J4*P4,0)
[/TD]
[TD="colspan: 2"]=IF(AA5>0,(J5-AA5)/J5*P5,0)
[/TD]
[TD="colspan: 2"]=IF(AA6>0,(J6-AA6)/J6*P6,0)
[/TD]
[TD="colspan: 2"]=IF(AA5>0,(J5-AA5)/J5*P5,0)
[/TD]
</tbody>
All of the data in columns A-V is being copied from another source and then pasted into this sheet. There is quite a bit of formatting, calculating etc.
I basically need a vba that will look in col H and then paste the appropriate formulas into AA-AG. The first row is different--the second could simply copy down until the value in H changes and then the first/second row would need to be inserted (with 2nd row being copied down) until the next change in value.
Hope this makes sense!
Any help would be greatly appreciated.
I am struggling with a part of a project I am working on and have been unable to find a solution. Hoping someone here can assist.
I need to be able to insert formulas into columns AA-AG, based on data (that is variable) in column H
I am calculating capital gains based on tax lots and the formulas are specific to that. There could be one tax lot per security or many. The first row of formula would need to correspond with the change in value (tickers) in column H. The second line would then be copied down for the remaining rows, until the value in col H changes.
H | AA | AB | AE | AF | AG | AH | ||
XXX | =IF($Z4<0,$K4+$Z4,0) | =IF(AA4<0, P4,0) | =IF(AA4<0,Q4,0) | =IF(AA4>0,(J4-AA4)/J4*Q4,0) | =SUM(AB4,AD4) | =SUM(AC4,AE4) | ||
XXX | =IF(AA4<0,AA4+K5,0) | =IF(AA5<0, P5,0) | =IF(AA5<0,Q5,0) | =IF(AA5>0,(J5-AA5)/J5*Q5,0) | =SUM(AB5,AD5) | =SUM(AC5,AE5) | ||
XXX | =IF(AA5<0,AA5+K6,0) | =IF(AA6<0, P6,0) | =IF(AA6<0,Q6,0) | =IF(AA6>0,(J6-AA6)/J6*Q6,0) | =SUM(AB6,AD6) | =SUM(AC6,AE6) | ||
YYY | =IF($Z4<0,$K4+$Z4,0) | =IF(AA4<0, P4,0) | =IF(AA4<0,Q4,0) | =IF(AA4>0,(J4-AA4)/J4*Q4,0) | =SUM(AB4,AD4) | =SUM(AC4,AE4) | ||
YYY | =IF(AA4<0,AA4+K5,0) | =IF(AA5<0, P5,0) | =IF(AA5<0,Q5,0) | =IF(AA5>0,(J5-AA5)/J5*Q5,0) | =SUM(AB5,AD5) | =SUM(AC5,AE5) | ||
YYY | =IF(AA5<0,AA5+K6,0) | =IF(AA6<0, P6,0) | =IF(AA6<0,Q6,0) | =IF(AA6>0,(J6-AA6)/J6*Q6,0) | =SUM(AB6,AD6) | =SUM(AC6,AE6) | ||
YYY | =IF(AA4<0,AA4+K5,0) | =IF(AA5<0, P5,0) | =IF(AA5<0,Q5,0) | =IF(AA5>0,(J5-AA5)/J5*Q5,0) | =SUM(AB5,AD5) | =SUM(AC5,AE5) | ||
YYY | =IF(AA5<0,AA5+K6,0) | =IF(AA6<0, P6,0) | =IF(AA6<0,Q6,0) | =IF(AA6>0,(J6-AA6)/J6*Q6,0) | =SUM(AB6,AD6) | =SUM(AC6,AE6) | ||
YYY | =IF(AA5<0,AA5+K6,0) | =IF(AA6<0, P6,0) | =IF(AA6<0,Q6,0) | =IF(AA6>0,(J6-AA6)/J6*Q6,0) | =SUM(AB6,AD6) | =SUM(AC6,AE6) | ||
ZZZ | =IF($Z4<0,$K4+$Z4,0) | =IF(AA4<0, P4,0) | =IF(AA4<0,Q4,0) | =IF(AA4>0,(J4-AA4)/J4*Q4,0) | =SUM(AB4,AD4) | =SUM(AC4,AE4) | ||
ZZZ | =IF(AA4<0,AA4+K5,0) | =IF(AA5<0, P5,0) | =IF(AA5<0,Q5,0) | =IF(AA5>0,(J5-AA5)/J5*Q5,0) | =SUM(AB5,AD5) | =SUM(AC5,AE5) | ||
ZZZ | =IF(AA5<0,AA5+K6,0) | =IF(AA6<0, P6,0) | =IF(AA6<0,Q6,0) | =IF(AA6>0,(J6-AA6)/J6*Q6,0) | =SUM(AB6,AD6) | =SUM(AC6,AE6) | ||
ZZZ | =IF(AA4<0,AA4+K5,0) | =IF(AA5<0, P5,0) | =IF(AA5<0,Q5,0) | =IF(AA5>0,(J5-AA5)/J5*Q5,0) | =SUM(AB5,AD5) | =SUM(AC5,AE5) | ||
<tbody>
[TD="colspan: 2"]AC
[/TD]
[TD="colspan: 2"]=IF(AA4>0,(J4-AA4)/J4*P4,0)
[/TD]
[TD="colspan: 2"]=IF(AA5>0,(J5-AA5)/J5*P5,0)
[/TD]
[TD="colspan: 2"]=IF(AA6>0,(J6-AA6)/J6*P6,0)
[/TD]
[TD="colspan: 2"]=IF(AA4>0,(J4-AA4)/J4*P4,0)
[/TD]
[TD="colspan: 2"]=IF(AA5>0,(J5-AA5)/J5*P5,0)
[/TD]
[TD="colspan: 2"]=IF(AA6>0,(J6-AA6)/J6*P6,0)
[/TD]
[TD="colspan: 2"]=IF(AA5>0,(J5-AA5)/J5*P5,0)
[/TD]
[TD="colspan: 2"]=IF(AA6>0,(J6-AA6)/J6*P6,0)
[/TD]
[TD="colspan: 2"]=IF(AA6>0,(J6-AA6)/J6*P6,0)
[/TD]
[TD="colspan: 2"]=IF(AA4>0,(J4-AA4)/J4*P4,0)
[/TD]
[TD="colspan: 2"]=IF(AA5>0,(J5-AA5)/J5*P5,0)
[/TD]
[TD="colspan: 2"]=IF(AA6>0,(J6-AA6)/J6*P6,0)
[/TD]
[TD="colspan: 2"]=IF(AA5>0,(J5-AA5)/J5*P5,0)
[/TD]
</tbody>
All of the data in columns A-V is being copied from another source and then pasted into this sheet. There is quite a bit of formatting, calculating etc.
I basically need a vba that will look in col H and then paste the appropriate formulas into AA-AG. The first row is different--the second could simply copy down until the value in H changes and then the first/second row would need to be inserted (with 2nd row being copied down) until the next change in value.
Hope this makes sense!
Any help would be greatly appreciated.