Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Make Text to Numbers Code More User Friendly

  1. #1
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    13

    Make Text to Numbers Code More User Friendly

    I would like to make the below code more flexible. Can someone show me a way that I can have the user input the column in a simple input box?

    So instead of having to go into the VB editor a novice could change the reference easily...

    Code:
    Sub FormatTextAsNumbers()
        Range("Q:Q").Select 'specify the range which suits your purpose
        With Selection
            Selection.NumberFormat = "General"
            .Value = .Value
             Columns("Q:Q").Select 'Changes Selection to two decimal format
        Selection.NumberFormat = "0.00"
        End With
    End Sub
    Using Excel 2010

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Try using this macro instead of the one you posted...
    Code:
    Sub FormatTextAsNumbers()
        Dim Col As Range
        Set Col = Application.InputBox("Please select a column...", Type:=8)
        Set Col = Columns(Col.Cells(1).Column)
        Col.NumberFormat = "General"
        Col.NumberFormat = "0.00"
    End Sub

  3. #3
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    13
    Code:
    Sub FormatTextAsNumbers()
        Dim Col As Range
        Set Col = Application.InputBox("Please select a column...", Type:=8)
        Set Col = Columns(Col.Cells(1).Column)
        Col.NumberFormat = "General"
        Col.NumberFormat = "0.00"
    End Sub
    Rick,

    The Input box works great now however, the little green tick marks that signify text is stored as a number do not seem to disappear when I test the code. Am I doing somthing wrong? I am using the code in conjunction with this other code but i do not think it would effect the result... :

    Code:
    Sub MacroShortcutList()
    'Standard Module code!
    'Display pick list box.
    Dim Message, Title, Default, MyPick
    
    'Set prompt.
    'Add other macros to list with & Chr(13) & "Macro Name"
    Message = "Select the number of the macro you want to run:" & Chr(13) & _
    "1.  Select No Macro" & Chr(13) & "2.  Run Cost Analysis at 50%" & Chr(13) & "3.  Customer Service Report" & Chr(13) & "4.  Delete Rows Based On Criteria" _
    & Chr(13) & "5.  Insert Piedmont Logo" & Chr(13) & "6.  Run Flat Rate Cost Analysis" & Chr(13) & "7.  Format Text to Numbers"
    
    
    'Set title.
    Title = "Select a Macro to run!"
    'Set default.
    Default = "1"
    
    'Display message, title, and default value.
    MyPick = InputBox(Message, Title, Default)
    'Optional, control box position!
    'Display dialog box at position 100, 100.
    'MyPick = InputBox(Message, Title, Default, 100, 100)
    
    Select Case MyPick
    
    Case 1
    MsgBox "No Macro Selected!"
    
    'Add additional Case code as needed!
    Case 2
    Call RunCostAnalysisFifty
    
    Case 3
    Call CustomerServiceReport
    
    Case 4
    
    Call DeleteRowsCriteria
    
    Case 5
    Call PiedmontLogo
    
    Case 6
    Call RunCostAnalysisFlatRate
    
    Case 7
    Call FormatTextAsNumbers
    
    Case Else
    Exit Sub
    
    End Select
    End Sub
    Using Excel 2010

  4. #4
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    13
    Rick,

    I always appreciate you taking the time to help me with code. I just tried the above code you provided again. I was certain that I must have missed something but, it still seems unsuccessful at changing numbers stored as text to two decimal number format. Is there something I am missing? I am supposed to enter columns in this format correct? $C:$C...

    Thanks for any insight.
    Using Excel 2010

  5. #5
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by mrmmickle1 View Post
    Rick,

    I always appreciate you taking the time to help me with code. I just tried the above code you provided again. I was certain that I must have missed something but, it still seems unsuccessful at changing numbers stored as text to two decimal number format. Is there something I am missing? I am supposed to enter columns in this format correct? $C:$C...
    Can you post a copy of your workbook with the unprocessed data in it so I can try the code out on your actual data in order to see what is happening (or not happening)?

  6. #6
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    13

    Text To Numbers

    Rick,

    Of course. Here is an example of what I am having trouble getting to change. The green tick marks in column C, as well as the formatting seem not to be changing as expected. Thanks again for the help.

    -Matt
    Attached Files Attached Files
    Using Excel 2010

  7. #7
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by mrmmickle1 View Post
    Rick,

    Of course. Here is an example of what I am having trouble getting to change. The green tick marks in column C, as well as the formatting seem not to be changing as expected. Thanks again for the help.
    It looks like this code may be working correctly...
    Code:
    Sub FormatTextAsNumbers()
        Dim Col As Range
        Set Col = Application.InputBox("Please select a column...", Type:=8)
        Set Col = Columns(Col.Cells(1).Column)
        Col.NumberFormat = "General"
        Col.NumberFormat = "0.00"
        Col.Value = Col.Value
    End Sub

  8. #8
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    13
    Rick,

    You are incredible. THanks so much for your efforts. I sampled the code and it of course works perfectly for my purposes. I was wondering... I have no purpose to speed this macro up but, just for good practice. If I wanted the same end result is it feasible to delete this portion of code?
    Code:
      Col.NumberFormat = "General"
    Using Excel 2010

  9. #9
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    or
    Code:
    Sub M_snb_002()
      on error resume next
      Application.InputBox("Please select a column...", Type:=8).EntireColumn.NumberFormat = "0.00"
    End Sub

  10. #10
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by mrmmickle1 View Post
    Rick,

    You are incredible. THanks so much for your efforts. I sampled the code and it of course works perfectly for my purposes. I was wondering... I have no purpose to speed this macro up but, just for good practice. If I wanted the same end result is it feasible to delete this portion of code?
    Code:
      Col.NumberFormat = "General"
    Yes, you can remove that line... it is left over from a previous test. You might want to consider using snb's code instead, though... besides being more compact, it also includes an error handler as well (although I like to turn the error handler off afterwards by putting an
    Code:
    On Error GoTo 0
    statement at the end).
    Last edited by Rick Rothstein; 11-18-2012 at 11:02 PM.

Similar Threads

  1. Remove Special Characters From Text Or Remove Numbers From Text
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 5
    Last Post: 05-31-2013, 04:43 PM
  2. Replies: 14
    Last Post: 05-25-2013, 06:55 AM
  3. Replies: 2
    Last Post: 05-13-2013, 12:03 AM
  4. Replies: 3
    Last Post: 04-05-2013, 08:24 AM
  5. tracking changes and prompt user
    By princ_wns in forum Excel Help
    Replies: 1
    Last Post: 01-22-2012, 03:37 PM

Posting Permissions

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