I have a formula in VBA that is calculated and displayed in a Label,
and then inserted into a cell,
I cannot get the darned thing to display as a Fraction or get it
formatted into the cell as a fraction
Here is the formula
Private Sub ListBox2_Change()
If ListBox2.Value = quot;H.W.R.quot; Then
Label17.Caption = TextBox4.Text - 1 / 8
Else
Label17.Caption = TextBox4.Text 1 / 8
End If
End Sub
Any IdeasHere is one, incredibly convoluted way
Dim saveValue
Dim saveFormat
With Range(quot;A1quot;)
saveValue = .Value
saveFormat = .NumberFormat
.Value = TextBox4.Text - 1 / 8
.NumberFormat = quot;#??/??quot;
If ListBox2.Value = quot;H.W.R.quot; Then
Label17.Caption = Format(TextBox4.Text - 1 / 8, quot;#??/??quot;)
Else
Label17.Caption = TextBox4.Text 1 / 8
End If
.Value = saveValue
.NumberFormat = saveFormat
End With--
HTH
Bob Phillips
(remove nothere from the email address if mailing direct)
quot;damorrisonquot; gt; wrote in message ups.com...
gt; I have a formula in VBA that is calculated and displayed in a Label,
gt; and then inserted into a cell,
gt;
gt; I cannot get the darned thing to display as a Fraction or get it
gt; formatted into the cell as a fraction
gt; Here is the formula
gt;
gt; Private Sub ListBox2_Change()
gt; If ListBox2.Value = quot;H.W.R.quot; Then
gt; Label17.Caption = TextBox4.Text - 1 / 8
gt; Else
gt; Label17.Caption = TextBox4.Text 1 / 8
gt; End If
gt;
gt; End Sub
gt;
gt; Any Ideas
gt;
Maybe something like:
Label17.Caption = Application.Text(cdbl(TextBox4.Text) - 1 / 8, quot;??/??quot;)
damorrison wrote:
gt;
gt; I have a formula in VBA that is calculated and displayed in a Label,
gt; and then inserted into a cell,
gt;
gt; I cannot get the darned thing to display as a Fraction or get it
gt; formatted into the cell as a fraction
gt; Here is the formula
gt;
gt; Private Sub ListBox2_Change()
gt; If ListBox2.Value = quot;H.W.R.quot; Then
gt; Label17.Caption = TextBox4.Text - 1 / 8
gt; Else
gt; Label17.Caption = TextBox4.Text 1 / 8
gt; End If
gt;
gt; End Sub
gt;
gt; Any Ideas
--
Dave Peterson
damorrison wrote:
gt; I have a formula in VBA that is calculated and displayed in a Label,
gt; and then inserted into a cell,
gt;
gt; I cannot get the darned thing to display as a Fraction or get it
gt; formatted into the cell as a fraction
gt; Here is the formula
gt;
gt; Private Sub ListBox2_Change()
gt; If ListBox2.Value = quot;H.W.R.quot; Then
gt; Label17.Caption = TextBox4.Text - 1 / 8
gt; Else
gt; Label17.Caption = TextBox4.Text 1 / 8
gt; End If
gt;
gt; End Sub
gt;
gt; Any Ideas
Do you want it as a mixed fraction or an improper fraction?
preferably 1/2, 1/4, 1/8,1/16,
But if I have to settle for /16's that's what I'll do
quot;Label17.Caption = Application.Text(cdbl(TextBox4.Text) - 1 / 8,
quot;??/??quot;) quot;..
That doesn't work for me all I get is the number in fractions such as 7
1/8 I get 57/8
quot;Label17.Caption = Application.Text(cdbl(TextBox4.Text) - 1 / 8,
quot;??/??quot;) quot;..
That doesn't work for me all I get is the number in fractions such as 7
1/8 I get 57/8Label17.Caption = Application.Text(CDbl(a) - 1 / 8, quot;# ??/??quot;)
or
Label17.Caption = Application.Text(CDbl(a) - 1 / 8, quot;# ??/16quot;)
damorrison wrote:
gt;
gt; quot;Label17.Caption = Application.Text(cdbl(TextBox4.Text) - 1 / 8,
gt; quot;??/??quot;) quot;..
gt;
gt; That doesn't work for me all I get is the number in fractions such as 7
gt; 1/8 I get 57/8
--
Dave Peterson
damorrison wrote:
gt; preferably 1/2, 1/4, 1/8,1/16,
gt; But if I have to settle for /16's that's what I'll do
I don't understand. If the fraction that needs to be displayed is say 5/16
wouldn' that be what you want?
But you didn't answer my question.
If I ask Excel to display 43.25 and format the cell as Fraction it'll
display it as a mixed number rather than an improper fraction. Is that what
you want? If so I find that the cell format works fine for me. What happens
when you put a number into a cell formatted as Fraction?
Please try to give full information so that I don't have to keep guessing
damorrison wrote:
gt; quot;Label17.Caption = Application.Text(cdbl(TextBox4.Text) - 1 / 8,
gt; quot;??/??quot;) quot;..
gt;
gt; That doesn't work for me all I get is the number in fractions such as
gt; 7 1/8 I get 57/8
Maybe it would help if you gave us an example of an input and the required
output. Your descriptions of what you want and what you are getting are
sparse and incomplete.
- Dec 18 Thu 2008 20:47
VBA won't format into fraction
close
全站熱搜
留言列表
發表留言
留言列表

