calculating stock market bonus shares

mwvirk

Active Member
Joined
Mar 2, 2011
Messages
295
Office Version
  1. 2016
Platform
  1. Windows
hello

I am calculating how many bonus shares (Flag marked as B) I have received from the stock market for each of my stocks
and then also checking if I sell some bonus shares then how many are still in my portfolio

in this excel file, I have 2 sheets
sheet1 is for buying, selling and bonus shares received
sheet2 is to check the status that how many bonus shares were received and how many are left. if all are sold then I should get 0 in sheet2 cell D
(but in all cases, I want to keep the actual bonus shares received in sheet2 cell C)

I have multiple issues here in this sheet2:

1- if the cell H in sheet1 is blank then cell D in sheet2 is not counting the total (i should have a value of 0 at least in sheet1 cell H to get the result since the blank cell is not showing the count in sheet2 cell D)
2- if I partially or fully sell bonus shares in sheet1 then it's showing balance zero in all cases in sheet2 cell D (i am checking here to know how many are still in my portfolio)

kindly check and help.

thanks


Test-Copy.xlsx
ABCDEFGH
1Stock nameFlagReceivedSold
2AppleR1000
3GoogleR1500
4IntelR2000
5FacebookR2500
6AppleB105
7GoogleB150
8IntelB200
9FacebookB250
10AppleR2000
11GoogleR2500
12IntelR3000
13FacebookR3500
14AppleB15
15GoogleB20
16IntelB25
17FacebookB30
Sheet1





Test-Copy.xlsx
ABCD
1Apple250
2Google3515
3Intel4520
4Facebook5525
Sheet2
Cell Formulas
RangeFormula
C1:C4C1=SUMIFS(Sheet1!F:F,Sheet1!A:A,A1,Sheet1!C:C,"B")
D1:D4D1=SUMIFS(Sheet1!F:F,Sheet1!A:A,A1,Sheet1!C:C,"B",Sheet1!H:H,0)
 
Thank you once again KRice for the detailed explanations and sorry for replying late as I was out of the station.
I tried applying your suggested changes from your last 2 posts and noticed that my desktop is hanging after all the above changes from the previous 2 posts. Also, I got a few errors in a few cells which were working fine before but maybe I have made a wrong change. I am sharing the screenshots and the mini sheet.

I am also thinking of following your suggested format. I am sharing the 3 records in my mini sheet. As you know what are my requirements for the sheet? I wish you can update these 3 records with all the formulas and condition checks and share the Excel file like before and then after the 3 records, I will start inputting the data again.

My total rows for the (only) NA# are 8161 and I have changed the formulas accordingly. The way my computer is hanging, I am afraid if I input the remaining PP/PB/PS/KP recording, my computer might burn or might take ages to input 1 single entry.

One more mistake I made, I didn't take the backup and applied all the changes from the last two posts. So, at this moment, I lost all the previous formulas. I can find all those but will take a lot of time. So, I wish we can fix the current sheet after all the changes:
1- to return the required output
2- minimize the CPU/Memory utilization and work fast. It's a gaming computer and my CPU max goes to 68 even I am playing COD/MOH/CRYSIS games :biggrin:
3- otherwise I wish you can make the changes in 3 records as you know my requirements and I will update the data again. I will listen to your suggestions to remove the merged cells but the output/layout requested by my office is the same as I have designed :(

Thank you once again and waiting for your helpful reply as usual.

Regards,
MWVirk


1664024871931.png


1664026097091.png





Election 2022.xlsx
ABCDEFGHIJKLMNOPQR
1NA # (2018)ProvinceNA # (2013)Seat NameRegistered VotersTotal Cast VotesRejected VotesValid Cast Votes% Of Total Registered VotesNA FlagCandidate NameParty NameVotes% Of Candidate VotesWinner's NameWinner PartyRunner up NameRunner up Party
2NA-001Kingdom ValleyBlue Area 1Blue Area 1A318,15030,50050030,0009.59%NA-001Candidate Name 0001Party Name AA1,0003.33%#N/A#N/A#NUM!#NUM!
3NA-001Candidate Name 0002Party Name AB1,0003.33%
4NA-001Candidate Name 0003Party Name AC7002.33%
5NA-001Candidate Name 0004Party Name AD1,0003.33%
6NA-001Candidate Name 0005Party Name AE1,0003.33%
7NA-001Candidate Name 0006Party Name AF1,0003.33%
8NA-001Candidate Name 0007Party Name AG1,0003.33%
9NA-001Candidate Name 0008Party Name AH1,1003.67%
10NA-001Candidate Name 0009Party Name AI1,0003.33%
11NA-001Candidate Name 0010Party Name AJ1,0003.33%
12NA-001Candidate Name 0011Party Name AK1,2004.00%
13NA-001Candidate Name 0012Party Name AL1,0003.33%
14NA-001Candidate Name 0013Party Name AM1,0003.33%
15NA-001Candidate Name 0014Party Name AN1,0003.33%
16NA-001Candidate Name 0015Party Name AO1,0003.33%
17NA-001Candidate Name 0016Party Name AP1,0003.33%
18NA-001Candidate Name 0017Party Name AQ1,0003.33%
19NA-001Candidate Name 0018Party Name AR1,0003.33%
20NA-001Candidate Name 0019Party Name AS1,0003.33%
21NA-001Candidate Name 0020Party Name AT1,0003.33%
22NA-001Candidate Name 0021Party Name AU1,0003.33%
23NA-001Candidate Name 0022Party Name AV1,0003.33%
24NA-001Candidate Name 0023Party Name AW1,0003.33%
25NA-001Candidate Name 0024Party Name AX1,0003.33%
26NA-001Candidate Name 0025Party Name AY1,0003.33%
27NA-001Candidate Name 0026Party Name AZ1,0003.33%
28NA-001Candidate Name 0027Party Name BA1,0003.33%
29NA-001Candidate Name 0028Party Name BB1,0003.33%
30NA-001Candidate Name 0029Party Name BC1,0003.33%
31NA-001Candidate Name 0030Party Name BD1,0003.33%
32NA-002Kingdom ValleyBlue Area 2Blue Area 2B318,15063,50050063,00019.96%NA-002Candidate Name 0001Party Name AA1,0001.59%#N/A#N/A#NUM!#NUM!
33NA-002Candidate Name 0002Party Name AB1,0001.59%
34NA-002Candidate Name 0003Party Name AC1,0001.59%
35NA-002Candidate Name 0004Party Name AD1,0001.59%
36NA-002Candidate Name 0005Party Name AE1,0001.59%
37NA-002Candidate Name 0006Party Name AF1,0001.59%
38NA-002Candidate Name 0007Party Name AG1,0001.59%
39NA-002Candidate Name 0008Party Name AH1,0001.59%
40NA-002Candidate Name 0009Party Name AI15,00023.81%
41NA-002Candidate Name 0010Party Name AJ1,0001.59%
42NA-002Candidate Name 0011Party Name AK1,0001.59%
43NA-002Candidate Name 0012Party Name AL1,0001.59%
44NA-002Candidate Name 0013Party Name AM1,0001.59%
45NA-002Candidate Name 0014Party Name AN1,0001.59%
46NA-002Candidate Name 0015Party Name AO1,0001.59%
47NA-002Candidate Name 0016Party Name AP1,0001.59%
48NA-002Candidate Name 0017Party Name AQ1,0001.59%
49NA-002Candidate Name 0018Party Name AR1,0001.59%
50NA-002Candidate Name 0019Party Name AS20,00031.75%
51NA-002Candidate Name 0020Party Name AT1,0001.59%
52NA-002Candidate Name 0021Party Name AU1,0001.59%
53NA-002Candidate Name 0022Party Name AV1,0001.59%
54NA-002Candidate Name 0023Party Name AW1,0001.59%
55NA-002Candidate Name 0024Party Name AX1,0001.59%
56NA-002Candidate Name 0025Party Name AY1,0001.59%
57NA-002Candidate Name 0026Party Name AZ1,0001.59%
58NA-002Candidate Name 0027Party Name BA1,0001.59%
59NA-002Candidate Name 0028Party Name BB1,0001.59%
60NA-002Candidate Name 0029Party Name BC1,0001.59%
61NA-002Candidate Name 0030Party Name BD1,0001.59%
62NA-003Kingdom ValleyBlue Area 3Blue Area 3C318,15030,50050030,0009.59%NA-003Candidate Name 0001Party Name AA1,0003.33%#N/A#N/A#NUM!#NUM!
63NA-003Candidate Name 0002Party Name AB1,0003.33%
64NA-003Candidate Name 0003Party Name AC1,0003.33%
65NA-003Candidate Name 0004Party Name AD1,0003.33%
66NA-003Candidate Name 0005Party Name AE1,0003.33%
67NA-003Candidate Name 0006Party Name AF1,0003.33%
68NA-003Candidate Name 0007Party Name AG1,0003.33%
69NA-003Candidate Name 0008Party Name AH1,0003.33%
70NA-003Candidate Name 0009Party Name AI1,0003.33%
71NA-003Candidate Name 0010Party Name AJ1,0003.33%
72NA-003Candidate Name 0011Party Name AK1,0003.33%
73NA-003Candidate Name 0012Party Name AL1,0003.33%
74NA-003Candidate Name 0013Party Name AM1,0003.33%
75NA-003Candidate Name 0014Party Name AN1,0003.33%
76NA-003Candidate Name 0015Party Name AO1,0003.33%
77NA-003Candidate Name 0016Party Name AP1,0003.33%
78NA-003Candidate Name 0017Party Name AQ1,0003.33%
79NA-003Candidate Name 0018Party Name AR1,0003.33%
80NA-003Candidate Name 0019Party Name AS1,0003.33%
81NA-003Candidate Name 0020Party Name AT1,0003.33%
82NA-003Candidate Name 0021Party Name AU1,0003.33%
83NA-003Candidate Name 0022Party Name AV1,0003.33%
84NA-003Candidate Name 0023Party Name AW1,0003.33%
85NA-003Candidate Name 0024Party Name AX1,0003.33%
86NA-003Candidate Name 0025Party Name AY1,0003.33%
87NA-003Candidate Name 0026Party Name AZ1,0003.33%
88NA-003Candidate Name 0027Party Name BA1,0003.33%
89NA-003Candidate Name 0028Party Name BB1,0003.33%
90NA-003Candidate Name 0029Party Name BC1,0003.33%
91NA-003Candidate Name 0030Party Name BD1,0003.33%
Election 2022 (MNA)
Cell Formulas
RangeFormula
H2,H62,H32H2=IF(COUNTIFS($J:$J,$J2,$M:$M,"<>")=COUNTIF($J:$J,$J2),SUMIF($J:$J,$A2,$M:$M),"")
I2,I62,I32I2=IF(OR(E2="",F2=""),"",F2/E2)
N2:N91N2=IF(COUNTIFS($J:$J,$J2,$M:$M,"<>")=COUNTIF($J:$J,$J2),$M2/SUMIF($J:$J,$J2,$M:$M),"")
O2,O62,O32O2=IF(COUNTIFS($J:$J,$J2,$M:$M,"<>")=COUNTIF($J:$J,$J2),INDEX($K$2:$K$8161,MATCH(1,($J$2:$J$8161=$A2)*($M$2:$M$8161=LARGE(($M$2:$M$8161)*($J$2:$J$8161=$A2),1)),0)),"")
P2,P62,P32P2=IF(COUNTIFS($J:$J,$J2,$M:$M,"<>")=COUNTIF($J:$J,$J2),INDEX($L$2:$L$8161,MATCH(1,($J$2:$J$8161=$A2)*($M$2:$M$8161=LARGE(($M$2:$M$8161)*($J$2:$J$8161=$A2),1)),0)),"")
Q2,Q62,Q32Q2=IF(COUNTIFS($J:$J,$J2,$M:$M,"<>")=COUNTIF($J:$J,$J2),INDEX($K$2:$K$8161,MATCH(1,($J$2:$J$8161=$A2)*($M$2:$M$8161=LARGE(($M$2:$M$8161)*($J$2:$J$8161=$A2),2)),0)),"")
R2,R62,R32R2=IF(COUNTIFS($J:$J,$J2,$M:$M,"<>")=COUNTIF($J:$J,$J2),INDEX($L$2:$L$8161,MATCH(1,($J$2:$J$8161=$A2)*($M$2:$M$8161=LARGE(($M$2:$M$8161)*($J$2:$J$8161=$A2),2)),0)),"")
F2,F62,F32F2=IF(H2="","",H2+G2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
F32:F8161Cell Value>$E$2textNO
F32:F8161Cell Value>0textNO
H32:H8161Cell Value>$E$2textNO
M3:N8161Expression=IF(COUNTIFS($J:$J,$J3,$M:$M,"<>")=COUNTIF($J:$J,$J3),AGGREGATE(14,6,($M$2:$M$8161)/($J$2:$J$8161=$J3),1)=$M3,FALSE)textNO
M3:N8161Expression=IF(COUNTIFS($J:$J,$J3,$M:$M,"<>")=COUNTIF($J:$J,$J3),AGGREGATE(14,6,($M$2:$M$8161)/($J$2:$J$8161=$J3),2)=$M3,FALSE)textNO
M2:N2Expression=IF(COUNTIFS($J:$J,$J2,$M:$M,"<>")=COUNTIF($J:$J,$J2),AGGREGATE(14,6,($M$2:$M$8161)/($J$2:$J$8161=$J2),1)=$M2,FALSE)textNO
M2:N2Expression=IF(COUNTIFS($J:$J,$J2,$M:$M,"<>")=COUNTIF($J:$J,$J2),AGGREGATE(14,6,($M$2:$M$8161)/($J$2:$J$8161=$J2),2)=$M2,FALSE)textNO
F2:F31Cell Value>$E$2textNO
F2:F31Cell Value>0textNO
H2:H31Cell Value>$E$2textNO
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
If adding the NA (or any other 2 digit) code is required, then I am OK to un-merge the A row rather inputting it again in J row. We can make use of the existing similar data as long the requirements met.
 
Upvote 0
I don't see any problem with the formulas that are producing errors; however, you will need to enter those formulas as array formulas. To do that, click on each cell, then click in the formula bar and hit F2 to go into Edit mode, then hit Ctrl-Shift-Enter simultaneously. You should see curly brackets surround the formula, indicating Excel is treating it as an array formula. Let me know if that makes the #N/A errors go away and if the expected results are delivered.
 
Upvote 0
getting the below error

I don't see any problem with the formulas that are producing errors; however, you will need to enter those formulas as array formulas. To do that, click on each cell, then click in the formula bar and hit F2 to go into Edit mode, then hit Ctrl-Shift-Enter simultaneously. You should see curly brackets surround the formula, indicating Excel is treating it as an array formula. Let me know if that makes the #N/A errors go away and if the expected results are delivered.
1664034130101.png


then i un-merge the cells for the first record and followed your instructions and it worked and i got the results:

1664034211721.png



and then mergred the cell for the 1st record and applied the same cells toward the end of the sheet.

it's working now. however the sheet is dead slow

thank you once again.
 
Last edited:
Upvote 0
Oh...yes, that is a good reminder and another reason to avoid merged cells. It sounds as if this reason alone makes array formulas impractical with merged cells and older versions of Excel (Excel 365 handles array formulas natively so I did not encounter this problem, even with merged cells). I will have another look at the formulas to see where some performance improvements could be made. If you are willing to consider the other format (with separate tables for: 1) organizing candidates in each voting region, 2) describing the voting regions and final results, and 3) tabulating voting results), then I wonder if you might also consider building the input side of the Voting Tabulation table (columns J:L in your example above) using Power Query? PQ would build the long table needed for tabulating votes, but there would be no formula "overhead". Once the file is setup with PQ, then the table would be built by renewing any candidate lists and hitting Data > Refresh All to construct the voting tabulation table.
 
Upvote 0
Oh...yes, that is a good reminder and another reason to avoid merged cells. It sounds as if this reason alone makes array formulas impractical with merged cells and older versions of Excel (Excel 365 handles array formulas natively so I did not encounter this problem, even with merged cells). I will have another look at the formulas to see where some performance improvements could be made. If you are willing to consider the other format (with separate tables for: 1) organizing candidates in each voting region, 2) describing the voting regions and final results, and 3) tabulating voting results), then I wonder if you might also consider building the input side of the Voting Tabulation table (columns J:L in your example above) using Power Query? PQ would build the long table needed for tabulating votes, but there would be no formula "overhead". Once the file is setup with PQ, then the table would be built by renewing any candidate lists and hitting Data > Refresh All to construct the voting tabulation table.
don't know what it would look like but if you think I cannot create the problem while working on the dashboard (shown in post #24) then I can try.
there was an other one you have shared but I really didn't understand how I can add more candidates and NA# etc

1664036912658.png
 
Upvote 0
Could you clarify a detail we discussed previously. If candidates a, b, and c are the only 3 candidates in NA-001, is it true then that NA-002, NA-003... (all of the NA's) also have only candidates a, b, and c, and no other candidates?

I understand your earlier explanation that some candidates might appear in other two-letter code categories. What do you call these two-letter codes with numbers...are they voting stations, precincts, districts? (I don't know what words to use to describe them).
 
Upvote 0
Could you clarify a detail we discussed previously. If candidates a, b, and c are the only 3 candidates in NA-001, is it true then that NA-002, NA-003... (all of the NA's) also have only candidates a, b, and c, and no other candidates?

I understand your earlier explanation that some candidates might appear in other two-letter code categories. What do you call these two-letter codes with numbers...are they voting stations, precincts, districts? (I don't know what words to use to describe them).
OK. let us make it clear to understand easily.

'NA' stands for National Assembly and has almost 250 to 300 from all over the country (it might be 250 or more or less - but this is the expected range of 250-300)
different areas are divided and so it goes like this: NA-001, NA-002... and so on.

Then the four provinces come into the country with different 2-digit codes - each province has a separate code and a number like PP-001, PP-002... and so on. similarly the other 3 provinces: PB, PS, KP

so, are the NA# PP# PB# PS KP# 2-digit clear?

Don't get confused with the candidate names. As I told you, these are the names (assume "Candidate Name 0001" is a first, second, and third name of a person = Michael Steven John) (so, you can read it like Candidate=Michael Name=Steven 0001=John) so, I am assuming 30 candidates from each 2-digit area. Now if the candidates are 30 then they must be having 30 different parties. 1 candidate cannot participate in 2 parties under 1 area (NA, PP, PS, PB, KP) but it is possible that we have 30 candidates from 25 different parties but the remaining 5 are 'Independent'

Similarly, the party name "Party Name AA" can be 3 words of any party.

in my sheet, I made all unique names for candidates and parties.

candidate name can be anything. any name you think can be put in any 8161 K2:K8161 rows but most of the names can be the same with a different party or the same party.
If KRice is participating from 1 NA# then he can be in any other NA# but your party will be the same. It's like you are presenting your party from multiple areas. Your every victory in any area will give 1 win to your party. Now you can be in multiple NA# but you cannot be from all the 300 NA# (maybe you can in 2, 5, 6, NA#)
Same way, you can be in NA# but also from any other province.

Hope it is clear!

(I have sent a private message if you have received it and if that's possible)
 
Upvote 0
1 candidate cannot participate in 2 parties under 1 area (NA, PP, PS, PB, KP)
this is applicable in all areas.
e.g. if KRice is NA#1 under the party XYZ then he cannot be part of any other party.

let's make it more clear... 1 physical person belongs to 1 party. he is the asset of 1 party. he cannot participate for any other party from any NA PP PS PB KP
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top