+ Reply to Thread
Results 1 to 4 of 4

Efficien loop code to format labels

  1. #1
    Registered User
    Join Date
    02-18-2009
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    1

    Efficien loop code to format labels

    Hi all,

    I am trying to creat a code that with take the value of an active cell and depending on this value will assign a backcolour to a label corresponding to the cell. so far so good.
    I then want the code to offset to the next cell in the range read its value and assign a colour to that cells backcolor.

    here is an idea.

    range("A1").select
    for n = 1 to 4
    if activecell = "A" then
    Label1.BackColor = RGB(0, 0, 0)
    else
    if activecell = "B" then
    Label1.BackColor = RGB(0, 0, 255)
    else
    if activecell = "C" then
    Label1.BackColor = RGB(0, 255, 0)
    end if
    activecell.offset(0,1).select
    next n

    Firstly I would like the next loop (refering to A2 in this example) to refer to Label2 not Label1 and so on.
    secondly the example would loop through 4 cells in one row (A1:A4) but I would like the code to apply to several rows ie (A1:D4).

    so thats 16 cell and 16 labels. I could code this in a very inefficient way but I am sure ther is a simple method.

    Any ideas? Be gentle

    flyhigh.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,447

    Re: Efficien loop code to format labels

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Efficien loop code to format labels

    Please also ensure you post links should you x-post the same Question in other forums

    http://www.mrexcel.com/forum/showthread.php?t=372010

  4. #4
    Registered User
    Join Date
    11-24-2008
    Location
    Bristol
    Posts
    3

    Re: Efficien loop code to format labels

    Efficien loop code to format labels

    --------------------------------------------------------------------------------

    Hi all,

    I am trying to creat a code that with take the value of an active cell and depending on this value will assign a backcolour to a label corresponding to the cell. so far so good.
    I then want the code to offset to the next cell in the range read its value and assign a colour to that cells backcolor.

    here is an idea.

    Please Login or Register  to view this content.
    Firstly I would like the next loop (refering to A2 in this example) to refer to Label2 not Label1 and so on.
    secondly the example would loop through 4 cells in one row (A1:A4) but I would like the code to apply to several rows ie (A1:D4).

    so thats 16 cell and 16 labels. I could code this in a very inefficient way but I am sure ther is a simple method.

    Any ideas? Be gentle

    flyhigh.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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