New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

Formatting on userform textbox

Macros, VBA, Excel Automation, etc.

Re: Formatting on userform textbox

Postby Apcbr » Mon May 28, 2012 9:54 pm

Functionally for my purposes...Awesome :-D
A lot better than the variable array, that was getting rather complex because I decided on adding a line of boxes at a time rather than 10 rows at once as maximum.


Thanks a million Sisyphus.
  • 0

Greetings,
Apcbr

Say what you mean, mean what you say :-)
Apcbr
Regular
 
Posts: 38
Joined: Apr 25, 2012
Reputation: 0
Excel Version: 2007

Re: Formatting on userform textbox

Postby sanketh145 » Wed Apr 13, 2016 2:16 am

Hi!

I'm a newbie to all this, and I stumbled upon this thread while searching for exactly this solution.

Sisyphus,
Brilliant work, and thank you!!

I do realize this is an old thread, but for the sake of completion:

I found a small bug in the FractionToDecimal code:
It does not work for numbers less than 1. For example, "1/2" will not give "0.5", instead it remains as "1/2". I have added a small snippet in between the code to solve this.

Hope this helps someone, somewhere!

Cheers!


Code: Select all
Public Function FractionToDecimal(ByVal Num As String) As Variant
   
    Dim Fd As Variant
    Dim S() As String
    Dim T() As String
    Dim Dn As Double
   
    S = Split(Num)
    If LBound(S) = UBound(S) Then
        T = Split(Num, "/")
        If LBound(T) = UBound(T) Then
            Fd = Num
        Else
            Fd = T(LBound(T)) / T(UBound(T))
        End If
    Else
        Fd = Val(S(LBound(S)))
        S = Split(S(UBound(S)), "/")
        If UBound(S) > LBound(S) Then
            Dn = Val(S(UBound(S)))
            If Dn = 0 Then Dn = 1
            Fd = Val(S(LBound(S))) / Dn * Sgn(Fd) + Fd
        End If
    End If
    FractionToDecimal = Fd
End Function
  • 0

sanketh145
Rookie
 
Posts: 1
Joined: Apr 13, 2016
Reputation: 0
Excel Version: 2007

Previous

Return to Macros and VBA Questions

Who is online

Users browsing this forum: Google [Bot] and 34 guests