Consulting

Results 1 to 14 of 14

Thread: Solved: Easy format Question

  1. #1
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location

    Solved: Easy format Question

    One to really test the Brains Trust

    How can I ensure that my combobox returns it's value in a "0%" format
    Kindest Regards,
    Mike

    I love to Excel

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Uo load it such

    [vba]

    Combobox1.AddItem Format(value,"0%")
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location
    Ahhhh......Mr.X

    [VBA]
    T1.AddItem Format(Value, "0%")
    [/VBA]
    Runtime Error 70:

    Permission Denied
    Kindest Regards,
    Mike

    I love to Excel

  4. #4
    Where is the code located ?
    You generally need a better address.
    e.g. if the code is in the form then :- "Me.T1.AddItem Format(Value, "0%")"
    I assume T1 is your combobox (strange naming convention !)
    I assume "Value" is your variable ? (What is it declared as ? and what is it's value at the time of execution ?)
    2+2=9 ... (My Arithmetic Is Mental)

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by tccmdr
    Ahhhh......Mr.X

    [vba]
    T1.AddItem Format(Value, "0%&quot
    [/vba] Runtime Error 70:

    Permission Denied
    Value was just used to show you where to post your value. I had no idea whether it was a variable, a range or what. You need to plugin the real value.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location
    Mr.X.....had to move to another PC

    My workbook contains an 'Audit' userform to review a supplier's compliance on a number of items.

    T1 through 9 refers to 9 separate comboboxes. Each share the same property rowsource - "Score". "Score" is a defined range of percentages from 0%, incrementing by 10%, to 100%. Selecting a percentage sets the compliance tolerence level required for a particular item.

    My problem, however, is when the value is selected, it's decimal format is shown. I want to see the percentage format
    Kindest Regards,
    Mike

    I love to Excel

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Don't use RowSources, it binds the combobox and I think that is a bad idea, load it with eth data as I showed.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location
    OK Mr.X, I did as you suggested

    As each combobox will be using the same scoring items, is there a way I can set up the "AddItem" list so I can attach it to all the comboboxes.

    That way I don't have to recreate the list for every combobox
    Kindest Regards,
    Mike

    I love to Excel

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Something like this

    [vba]

    LoadCombo Me.ComboBox1
    LoadCombo Me.ComboBox2
    'etc


    Private Sub LoadCombo(ByRef cb AsMSForms.CombBox)

    With cb

    .Additem Format(value1,"0%&quot
    .Additem Format(value2,"0%&quot
    .Additem Format(value3,"0%&quot
    'etc
    End With
    End Sub
    [/vba]

    with real values of course
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location
    Mr.X

    I'm still getting errors....

    [VBA]
    Private Sub UserForm_Activate()
    LoadCombo Me.To1
    LoadCombo Me.To2
    LoadCombo Me.To3
    LoadCombo Me.To4
    LoadCombo Me.To5
    LoadCombo Me.To6
    LoadCombo Me.To7
    LoadCombo Me.To8
    LoadCombo Me.To9
    End Sub
    Private Sub LoadCombo(ByRef cb As MSForms.CombBox)

    With cb

    .AddItem Format(0, "0%")
    .AddItem Format(0.1, "0%")
    .AddItem Format(0.2, "0%")
    .AddItem Format(0.3, "0%")
    .AddItem Format(0.4, "0%")
    .AddItem Format(0.5, "0%")
    .AddItem Format(0.6, "0%")
    .AddItem Format(0.7, "0%")
    .AddItem Format(0.8, "0%")
    .AddItem Format(0.9, "0%")
    .AddItem Format(1, "0%")

    End With
    End Sub
    [/VBA]
    Kindest Regards,
    Mike

    I love to Excel

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I missed a letter

    [vba]

    Option Explicit

    Private Sub cmdOK_Click()
    Me.Hide
    End Sub

    Private Sub cmdQuit_Click()
    Me.Hide
    End Sub

    Private Sub UserForm_Activate()
    LoadCombo Me.To1
    LoadCombo Me.To2
    LoadCombo Me.To3
    LoadCombo Me.To4
    LoadCombo Me.To5
    LoadCombo Me.To6
    LoadCombo Me.To7
    LoadCombo Me.To8
    LoadCombo Me.To9
    End Sub
    Private Sub LoadCombo(ByRef cb As MSForms.ComboBox)

    With cb

    .AddItem Format(0, "0%")
    .AddItem Format(0.1, "0%")
    .AddItem Format(0.2, "0%")
    .AddItem Format(0.3, "0%")
    .AddItem Format(0.4, "0%")
    .AddItem Format(0.5, "0%")
    .AddItem Format(0.6, "0%")
    .AddItem Format(0.7, "0%")
    .AddItem Format(0.8, "0%")
    .AddItem Format(0.9, "0%")
    .AddItem Format(1, "0%")

    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  12. #12
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location
    Mr.X

    I must be going blind

    Which letter did you miss
    Kindest Regards,
    Mike

    I love to Excel

  13. #13
    VBAX Regular
    Joined
    May 2007
    Posts
    81
    Location
    Mr.X.........'o' Found it



    Thanks again for your help
    Kindest Regards,
    Mike

    I love to Excel

  14. #14
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Easy format Question

    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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