VBA - Calculate Percentage Values

Ananthak275

Board Regular
Joined
Aug 22, 2020
Messages
128
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
Got a table that starts on B5 and C5. I want to get the following calculations:

Latvia (b5)Russia (c5)
Lacrosse25
Hockey5
Basketball1
Football1
Soccer11

i want to calculate the following:
1. Percentage of total overlap of sports played in both Countries, each row gets 1 value is played in both sports, dived by the total number of sports (in this example 5). So this one would be Lacrosse and Soccer which is two sports, hence output would be 2/5 = 40%. Output should be in cell A1. Just the percentage in a1.
2. how many are played ONLY in Latvia. In this example: Basketball and Football so 2/5 = 40%. Output should be in cell B1. Just the percentage in B1.
3. how many are played ONLY in Russia. In this example: Hockey so 1/5 = 10%. Output should be in cell C1. Just the percentage in c1.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Like this perhaps ...

ABCDE
140%40%20%
2BothLatviaRussia
3
4
5LatviaRussia
6Lacrosse25
7Hockey5
8Basketball1
9Football1
10Soccer11
11
Sheet1
Cell Formulas
RangeFormula
A1A1=1-SUM(B1:C1)
B1B1=SUMPRODUCT(ISNUMBER(C6:C10)*ISBLANK(D6:D10))/ROWS(B6:B10)
C1C1=SUMPRODUCT(ISNUMBER(D6:D10)*ISBLANK(C6:C10))/ROWS(B6:B10)

But I'd do it differently if you were scaling up to more than two countries?
 
Upvote 0
Like this perhaps ...

ABCDE
140%40%20%
2BothLatviaRussia
3
4
5LatviaRussia
6Lacrosse25
7Hockey5
8Basketball1
9Football1
10Soccer11
11
Sheet1
Cell Formulas
RangeFormula
A1A1=1-SUM(B1:C1)
B1B1=SUMPRODUCT(ISNUMBER(C6:C10)*ISBLANK(D6:D10))/ROWS(B6:B10)
C1C1=SUMPRODUCT(ISNUMBER(D6:D10)*ISBLANK(C6:C10))/ROWS(B6:B10)

But I'd do it differently if you were scaling up to more than two countries?
Hi,

I considered doing it through formulas but I need VBA script. Sorry
 
Upvote 0
I considered doing it through formulas but I need VBA script. Sorry
Sorry from me too. I read the question too quickly and didn't see VBA in the header.

Why do you need VBA for such a trivial example? On re-reading properly, this looks to me like an assignment question?
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,164
Members
448,870
Latest member
max_pedreira

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