Consulting

Results 1 to 2 of 2

Thread: converting gram to lbs vba - two decimals after point requirement

  1. #1

    converting gram to lbs vba - two decimals after point requirement

    hello,
    I would like to convert the weight in grams typed in by the user in lbs . I would like it rounded to two decimal places after zero and if the value in lbs is less than one lb ,then i would like the no to begin with a single zero example 0.41 lbs.

    I have this code

    '1


    'setting weight of item in grams
    Dim wt1 As Range
    Set wt1 = ActiveDocument.Bookmarks("wt1").Range
    wt1.Text = Me.TextBox3.Value
    'converting weight to lbs
    Dim convert As Double
    convert1 = Val(wt1) * 0.0022
    convert1 = Format(convert1, "####.##")
    Dim lb1 As Range
    Set lb1 = ActiveDocument.Bookmarks("lb1").Range
    lb1 = convert1

    however, i do not get the zero before decimal if value of weight is less than 1 lb.
    Thank you for your help!

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    convert1 = Format(convert1, "0.00")
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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