Solved

Is it possible to highlight Excel VBA Listbox items in red according to certain criteria ?

Posted on 2013-11-16
4
663 Views
Last Modified: 2013-12-09
Hi,

I have an Excel application with an Orders userform containing a listbox. I'd like to highlight the text of those Listbox items which haven't yet been invoiced (I use a status text box to determine this).

Any ideas ?

thanks
Toco
0
Comment
Question by:Tocogroup
  • 3
4 Comments
 
LVL 11

Expert Comment

by:Gregory Miller
ID: 39653797
ListBox1.Clear
Dim c As Long
c = 1
For Each cll In Range("Table1").Columns(1).SpecialCells(xlCellTypeVisible).Cells
    ListBox1.AddItem cll.Value
    If Cells(cll, 5).Value <> "" Then
        ListBox1.items(c).ForeColor = vbRed
    End If
    c = c + 1
Next cll
0
 

Author Comment

by:Tocogroup
ID: 39654210
Thanks for your help.

I load my listbox from an array in one single statement for speed and efficiency.....

   liSales.List = SalesArray()

Is it possible to act on the listbox items directly, in some way or another? For example......

      If  liSales.Items(rowno,colno).Value <> "Invoiced"  Then
           liSales.Items(row).ForeColor = vbRed
      End If

I tried the above but I couldn't get it to work
0
 

Accepted Solution

by:
Tocogroup earned 0 total points
ID: 39654227
I tried your code too and couldn't get that to work either. Did you test your code ?
0
 

Author Closing Comment

by:Tocogroup
ID: 39705745
No further response from members.
I found out elsewhere that Listbox controls cannot be formatted in the way I wish. However ListView controls (an Add-in) are  formattable.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question