You are on page 1of 4

How do I display a ratio in Excel in the format A:B?

I have an Excel spreadsheet of data like: ClmAClmB oun oun 3 3 1 1 2 5 5 6 4 What i would like to do is add a third column which shows the ratio of columnA to columnB in the format of A:B. For example: ClmAClmB oun oun 3 3 1 1 2 5 5 6 4 Rto ai 31 : 51 : 32 :

Does anyone know of a way to achieve this? Thanks in advance.


excel

edited Jan 23 '09 at 14:21

asked Jan 23 '09 at 14:04 Vincent 138 1 1 7

feedback

7 Answers
You are looking for the greatest common divisor (GCD). You can calculate it recursively in VBA, like this: Fnto GDnmrtrA Itgr dnmntrA Itgr ucin C(ueao s nee, eoiao s nee) I dnmntr=0Te f eoiao hn GD=nmrtr C ueao Es le GD=GDdnmntr nmrtrMddnmntr C C(eoiao, ueao o eoiao) EdI n f EdFnto n ucin And use it in your sheet like this: ClmA oun 1 3 3 2 2 5 ClmB oun 1 1 5 ClmC oun =1GDA;B)&""&B/C(1 B) A/C(1 1 : 1GDA; 1 =2GDA;B)&""&B/C(2 B) A/C(2 2 : 2GDA; 2

It is recommendable to store the result of the function call in a hidden column and use this result to avoid calling the function twice per row: ClmA oun 1 3 3 2 2 5 ClmB oun 1 1 5 ClmC oun =C(1 B) GDA; 1 =C(2 B) GDA; 2 ClmD oun =1C &""&B/1 A/1 : 1C =2C &""&B/2 A/2 : 2C

answered Jan 23 '09 at 14:23 Tomalak 109k 14 129 254

Just so you know, Excel has a GCD function. You don't really need VBA for this solution at all:) office.microsoft.com/en-us/excel/HP052091041033.aspx Aaron Bush Mar 22 '10 at 12:10 @Aaron: Just so you know ;-), this cell function does not seem to be available before Excel 2007. Believe it or not, not everybody has switched yet. Tomalak Mar 22 '10 at 12:43 As you might have guessed I am using 2007. However I did check first. This article says it applies to 2003 office.microsoft.com/en-us/excel/HP052091041033.aspx Aaron Bush Mar 25 '10 at 12:50 @Aaron this is a programming related site.. what's the fun of doing it just by calling the Excel's function.. :) Lipis Jul 16 '10 at 21:06 @Lipis: Heh. :-P Tomalak Jul 16 '10 at 21:10

feedback

Try this formula: =USIUETX(1B,??)"""" SBTTT(ETA/1"/",/,:) Result: A 3 3 2 5 6 B 1 1 5 4 C 31 : 51 : 32 :

Explanation: TEXT(A1/B1,"?/?") turns A/B into an improper fraction SUBSTITUTE(...) replaces the "/" in the fraction with a colon This doesn't require any special toolkits or macros. The only downside might be that the result is considered text--not a number--so you can easily use it for further calculations.

Note: as @Robin Day suggested, increase the number of question marks (?) as desired to reduce rounding (thanks Robin!).
edited Jan 23 '09 at 14:30 answered Jan 23 '09 at 14:10 Michael Haren 29.3k 14 85 141

To make this formula more accurate you can replace it with =SUBSTITUTE(TEXT(A1/B1,"??????????/??????????"),"/",":") This makes rounding issues less likely. Robin Day Jan 23 '09 at 14:20 +1 for simplicity. Patrick Cuff Jan 23 '09 at 14:31 +1 for coolness Sam Oct 5 '11 at 13:52

feedback

The second formula on that page uses the GCD function of the Analysis ToolPak, you can add it from Tools > Add-Ins. =A1/GCD(A1,B1)&":"&B1/GCD(A1,B1)

This is a more mathematical formula rather than a text manipulation based on.
answered Jan 23 '09 at 14:12 Robin Day 24.1k 8 47 97 feedback

Lets assume you have data in D and E cells.. Here is an easiest ratio displaying fn by my frnd 'Karthik' =ON(7E,2 &: &(7E) RUDD/7 ) "" E/7
edited Nov 23 '11 at 9:43 ho1 26.5k 5 25 47 answered Jul 4 '11 at 11:05 KK. 234 1 4 11

feedback

I found this being easiest and shortest, I however rounded off to zero decimal places: ="1" & ":" & ROUND((A1/B1),0) note the spaces before and after & what this means is that "1" and ":" are seen as additional non-formula information to the overall formula The ROUND function round off A1/B1 which is the basic formula to 0 decimal places. you can try changing to 1,2,3....decimal places. I hope I made this simple
edited May 4 '12 at 14:51 Darren Davies 7,902 3 10 40 feedback answered Mar 9 '11 at 12:15 Rodgers 11 1

Thanks ya'll. I used this: =OCTNT(nme1GDnme1nme2)""(nme2GDnme1nme2)) CNAEAE(ubr/C(ubr,ubr),:,(ubr/C(ubr,ubr)) If you've got 2007 this works great.
edited Nov 23 '11 at 9:41 ho1 26.5k 5 25 47 feedback answered Jul 16 '10 at 20:59 Noah G 1

Below is the formula I use. I had a problem using GCD, because I use fairly large numbers to calculate the ratios from, and I found ratios such as "209:1024" to be less useful than simply rounding so it displays either "1:" or ":1". I also prefer not to use macros, if at all possible. Below is the result. =FA>1(RUDA/10)""(1B),(1A)""(ON(1A,)) I(1B,(ON(1B,)&:&B/1)(A/1&:&RUDB/10)) Some of the formula is unnecessary (e.g., "A1/A1"), but I included it to show the logic behind it. Also, you can toggle how much rounding occurs by playing with the setting on each ROUND function.
edited Nov 23 '11 at 9:43 ho1 26.5k 5 25 47 answered Aug 11 '10 at 21:41 JBabb 1

feedback

Not the answer you're looking for? Browse other questions tagged excel or ask your own question.

You might also like