Results 1 to 7 of 7

Thread: NumberFormat

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    56

    NumberFormat

    When i give th following
    mysht.columns(13).numberformat ="0.00"
    i get following results in column 13 763.00 instead of 763.44
    1830.00 instead of 1829.52

    Pl help me get the exact results
    Regards
    Samyo

  2. #2
    Addicted Member
    Join Date
    Jan 2006
    Posts
    234

    Re: NumberFormat

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim oneVal
    3. oneVal = Val(Text1)
    4.  
    5. Dim twoVal
    6. twoVal = Val(Form2)
    7.  
    8. Dim GROWVal
    9. GROWVal = Val(Text1) + Val(Text2)
    10.  
    11.  
    12.  
    13.  
    14. MsgBox "YOUR TOTAL IS $" & Format(GROWVal, "0.00"), , "OK TO EXIT"
    15.  
    16. End Sub

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: NumberFormat

    Use this...
    VB Code:
    1. mySht.Columns(13).NumberFormat = "0.00"
    2. 'Or
    3. mySht.Columns("M").NumberFormat = "0.00"
    Works fine for me in a new worksheet.

    Moved
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    56

    Re: NumberFormat

    Somehow does not work it rounds off to .00 and exact decimal nos i dont get after decimal places

    regds

    Samyo

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: NumberFormat

    How are you executing the code and do you have anyother formatting code on it?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Lively Member
    Join Date
    Feb 2006
    Posts
    96

    Re: NumberFormat

    I believe you have to declare it as variable number in stead - so it will be
    VB Code:
    1. mysht.columns(13).numberformat ="#.##"
    I you wan't to put in 1,000 separators, then you can do like this #,#,#.## for instance.

    Try experimenting using the format cells --> custom in your worksheet - it should give you a clue of what you can do...

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: NumberFormat

    posted code in #3 works correct and rounds to two places after the decimal point.

    Enable macros and check out column "M". enter in some numbers with at least to the thousandths.


    Containing code:


    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Workbook_Open()
    4.     Sheet1.Columns("M").NumberFormat = "0.00"
    5. End Sub
    Attached Files Attached Files
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width