Results 1 to 4 of 4

Using a "Do Until" loop to convert decimal numbers to hexadecimal

Threaded View

  1. #1
    Registered User
    Join Date
    10-13-2014
    Location
    Portland,Oregon
    MS-Off Ver
    2013
    Posts
    2

    Using a "Do Until" loop to convert decimal numbers to hexadecimal

    I am working on program that requires I use a Do-Until Loop to convert a decimal number to hexadecimal number. The following UDF makes Excel freeze up every time I run it, but it works great when I take out the do-until loop. Is there a better way to use a Do-Until Loop in this function?

    Function DecHexConverter(DecValue As String) As String
    Dim sTemp As String
    
    Do Until DecValue = ""
        If DecValue >= 16 Then
                'if greater than 16 then recall function
                sTemp = DecHexConverter(DecValue \ 16) & DecHexConverter(DecValue Mod 16)
        
        ElseIf DecValue > 9 And DecValue < 16 Then
                'if between 10 and 15 Assign A-F
                Select Case DecValue
                    Case "10"
                        sTemp = "A"
                    Case "11"
                        sTemp = "B"
                    Case "12"
                        sTemp = "C"
                    Case "13"
                        sTemp = "D"
                    Case "14"
                        sTemp = "E"
                    Case "15"
                        sTemp = "F"
                End Select
        Else
                'If between 0 and 9 no change
                sTemp = DecValue
        End If
    
    Loop
        DecHexConverter = sTemp
           
    End Function
    Last edited by JBeaucaire; 10-13-2014 at 01:44 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Excel 2007: How to Convert "5/2/2013" to "May" then subtract a Month so it's "Apr"
    By Golom in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-19-2013, 02:00 AM
  2. Removing digits after decimal in "text" numbers
    By jermsalerms in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-21-2006, 01:52 PM
  3. Replies: 2
    Last Post: 04-04-2006, 04:50 AM
  4. convert "37:30:55" to decimal
    By Teaman in forum Excel General
    Replies: 2
    Last Post: 11-04-2005, 10:25 AM
  5. CONVERT HEXADECIMAL CELL TO DECIMAL NUMBER
    By JAY in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-24-2005, 11:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1