Speak Fractions

johndrew

Board Regular
Joined
Apr 21, 2007
Messages
100
I am wanting to have a macro start on C2 read and speak, then go to D2 read and speak, then E2
and read and speak the value in the cell in Columns D and E are in fractions. Then next row
For Example

="item" & C2
"Height" & "D2" then read ="Width" & E2

I have A in C2 and 12.5 in D2 and 14.0625 in E2
Which would result in it speaking

Item A Height 12 and one half, Width fourteen and one eighth
then next row.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
The function to convert the decimal part into text is pretty basic, but, it suffices to demonstrate how to build up the output string.

Rich (BB code):
Option Explicit


Sub SayWhat()
   Dim sSpeak As String
   Dim frac As Double
   
   With Sheets("Sheet1").Range("C2")
      sSpeak = "Item " & .Value
   End With
   
   With Sheets("Sheet1").Range("D2")
      frac = .Value - Int(.Value)
      sSpeak = sSpeak & " height " & Int(.Value) & GetFraction(frac)
   End With
   
   With Sheets("Sheet1").Range("E2")
      frac = .Value - Int(.Value)
      sSpeak = sSpeak & " width " & Int(.Value) & GetFraction(frac)
   End With
   
   Application.Speech.Speak sSpeak
End Sub


Private Function GetFraction(ByVal fraction As Double) As String
   Select Case fraction
      Case 0.0625
         GetFraction = " and an eighth, "
      Case 0.25
         GetFraction = " and a quarter, "
      Case 0.5
         GetFraction = " and a half, "
         '
         'others
         '
      Case Else
         GetFraction = ""     'zero passed
   End Select
End Function
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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