Consulting

Results 1 to 12 of 12

Thread: UserForm(Excel/Project/MSForms) - Color/Font List Box

  1. #1
    VBAX Newbie
    Joined
    May 2007
    Posts
    5
    Location

    Smile UserForm(Excel/Project/MSForms) - Color/Font List Box

    The problem I'm having is that when I create a user form and try to add my list to it....I would like to be able to have two different colors witing one list box. Is there a way to do this? The idea is if a condition is negative the particular row would be red and if the condition is positive then i want the item to be green. It seems like no matter what they all come out the same color!!

    Thank you for your time and help!

    Brian

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Brian

    Short answer - No.

    Listbox items can't have different colours.

  3. #3
    VBAX Newbie
    Joined
    May 2007
    Posts
    5
    Location

    Question There is no way around it?

    There's no way to use some Array to reference the item in the list and use .FontColor based on a Select Case or If Condition??? It just seems like they should add this functionality don't you think??? The Font Property doesn't even show a color........shows everything else.....

    So for instance if you were to say

    ListBox.ListBox1(i) and reference the line when you load it in and make the text going into the box a certain color?? Ughhhhhh

    Help

  4. #4
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Suggestions:

    You could use two listboxes - one showing negative, the other positive values, or

    You could have a button near a (single) list box to flick between the negative and positive values, and load the values accordingly
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  5. #5
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Maybe you could take a look at the listview control. This control can change the forecolor of a listviewitem based on a certain condition.

  6. #6
    VBAX Newbie
    Joined
    May 2007
    Posts
    5
    Location

    Lightbulb How??

    Charlize;

    Great idea....I have no idea how to use that Contol with VBA within my form. Can you provide some sample code of how to do this? I've downloaded and installed the control, but stumped on how to make it control the forecolor on a listitem.

    Thanks,

    Brian

  7. #7
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Take a look at this kb article : http://vbaexpress.com/kb/getarticle.php?kb_id=916 to get you started.

  8. #8
    VBAX Newbie
    Joined
    May 2007
    Posts
    5
    Location

    Question Just about there

    Charlize;

    This is excellent...I'm just about there.......I'm using Microsoft Project VBA instead though.....and I'm having difficulty a bit with the syntax on the form itself. I've gotten everything else done....however......I'm not sure how to write the item/sub item part. Let's say I have 5 columns and 4 rows. If the value in Column number 4 for row 1 is a negative number then I would like the entire ForeColor of that row to be red. If it's a positive value, then I'd like it to be Green. The process would repeat for each row until completion. Can you maybe provide me with the corresponding syntax to equate ProjectVBA from the Excel VBA.....you reference the worksheet....and I'm using somewhere I reference the ActiveProject.....but not sure how the AddItem and the Array values and subitems come into play. Let's just say Column 1 is ID, Column 2 is Task Name, Column3 is StartDate and Column4 is Slack. So if Column4's first character is a "-" Then Forecolor = Red (somehow?!) and if not's then the row should be green!

    Thanks for the help

    Best Regards,

    Brian

  9. #9
    VBAX Newbie
    Joined
    May 2007
    Posts
    5
    Location

    Question Got it....but still need some assistance!

    Charlize;

    Figured it out....tricky stuff to convert to ProjectVBA for a newbie but is there a way to click on each of the column headings and sort by them in this listview?



    Thanks,

    Brian

  10. #10
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    This is an enhancement on the link I gave you. It will sort the columnheader named Client :[vba]Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    'If clicked on the columnheading named Client -> do the sorting
    If ColumnHeader.Text = "Client" Then
    Me.ListView1.Sorted = True
    Me.ListView1.SortKey = 0
    If Me.ListView1.SortOrder = lvwDescending Then
    Me.ListView1.SortOrder = lvwAscending
    Else
    Me.ListView1.SortOrder = lvwDescending
    End If
    Else
    Me.ListView1.Sorted = False
    End If
    End Sub[/vba]ps. Sorry I couldn't help with the converting to Project (but I don't know J *** S *** about Project).
    Last edited by Charlize; 05-30-2007 at 12:06 AM.

  11. #11
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Brian

    The only difference between Excel VBA and Project VBA should only be the object model and I don't see how that would affect your use of a listview control on a userform.

  12. #12
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Quote Originally Posted by Charlize
    This is an enhancement on the link I gave you. It will sort the columnheader named Client :[vba]Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
    'If clicked on the columnheading named Client -> do the sorting
    If ColumnHeader.Text = "Client" Then
    Me.ListView1.Sorted = True
    Me.ListView1.SortKey = 0
    If Me.ListView1.SortOrder = lvwDescending Then
    Me.ListView1.SortOrder = lvwAscending
    Else
    Me.ListView1.SortOrder = lvwDescending
    End If
    Else
    Me.ListView1.Sorted = False
    End If
    End Sub[/vba]ps. Sorry I couldn't help with the converting to Project (but I don't know J *** S *** about Project).
    Was it usefull ?

Posting Permissions

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