+ Reply to Thread
Results 1 to 6 of 6

Fast Loop for Forecolor change in Listview

  1. #1
    Registered User
    Join Date
    09-11-2015
    Location
    Hamilton, ON Canada
    MS-Off Ver
    2013
    Posts
    32

    Fast Loop for Forecolor change in Listview

    Hi All,

    I been working on changing the forecolor of a ListView SubItem based on a True or False value stored on a Sheet. I originally had a code working with an IF Statement that was placed in the For Next loop that loads Sheet1 (4500 rows and 16 columns) into Listview. Placing the IF statement in the loop slowed down the initialization of ListView dramatically. I've been working on a faster solution and almost have it with the exception of the getting ListView to recognize the rngY (range of cells TRUE) as the rows to color red.

    Can someone help me figure this last line out?

    Thanks

    BigD


    Please Login or Register  to view this content.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Fast Loop for Forecolor change in Listview

    Attaching a sample workbook enables others to work on your problem:

    To attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    To add a file to a new post

    To add a file to an existing post.

  3. #3
    Registered User
    Join Date
    09-11-2015
    Location
    Hamilton, ON Canada
    MS-Off Ver
    2013
    Posts
    32

    Re: Fast Loop for Forecolor change in Listview

    Here is the test file. Its set up to change TRUE to bold. The line above the Test font.bold is the one I'm trying to get working.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Fast Loop for Forecolor change in Listview

    Use the rngY row number to reference the ListView item index
    ListView1.ListItems(rngY.Row)....

    Try something like this...
    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 11-01-2015 at 02:05 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Registered User
    Join Date
    09-11-2015
    Location
    Hamilton, ON Canada
    MS-Off Ver
    2013
    Posts
    32

    Re: Fast Loop for Forecolor change in Listview

    Thank you Alpha!

    In my test file I got a Index Out Of Bounds error. I subtracted 1 from the row index (as below) and its working fine. I attached the updated test file.

    ListView1.ListItems(rngY.Row - 1).ListSubItems(1).ForeColor = vbRed

    In my main file that I've added this to, I did not get an Index Out Of Bounds error, but the red forecolor was out by one row down.
    ie.. row 2 = TRUE, row 3 subitem 1 was red.

    Subtracting 1 row corrected the problem, and the initialization time is much faster than when I added a IF Statement to the loop.

    Now I am going to add this to the search sub and see if it will maintain the red forecolor after a search is preformed.

    Again Thank you

    BigD

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Fast Loop for Forecolor change in Listview

    I didn't look at your example file when I made the suggestion. It matters which row is the start row for the ListView data. Then the row is offset to the list index. Looks like you did it correctly. Well done and you're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Change tab forecolor multipage UserForm
    By john55 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2014, 06:08 AM
  2. [SOLVED] Change code to be used to populate listview
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-03-2013, 05:49 PM
  3. Change listItem forecolor based on criteria
    By ioncila in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-15-2012, 10:03 AM
  4. Listview checked row delete line in Listview and in worksheet data
    By madforit in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2012, 01:00 PM
  5. fast way to change multiple cell locations in code??
    By fuston05 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-04-2010, 07:28 AM
  6. Text Box Change Using Listview
    By hifliers in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2009, 03:42 AM
  7. Formula to change RGB to/from .Fill.Forecolor?
    By Air_Cooled_Nut in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-29-2006, 01:12 PM
  8. Replies: 1
    Last Post: 04-01-2005, 02:06 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1