+ Reply to Thread
Results 1 to 6 of 6

Help looping until a certain cell value

  1. #1
    Registered User
    Join Date
    05-25-2011
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    52

    Help looping until a certain cell value

    Ok, this is going to be easy for anyone comfortable with vba to answer. I however am a beginner. My goal is simple, but I wanted to do it through code, just to challenge myself. What I want to do is go down the row and if column E is a certain value, highlight A-E in that row to be a certain color. So if E3 is the number 2, I want A2:E2 to be highlighted orange. Likewise if E7 is the number 4 I want A7:E7 to be highlight blue. Make sense? Alright here's the code I wrote to attempt to make it work:

    Please Login or Register  to view this content.
    I know where I'm going wrong. It's the "Range("A& cellnumber:E& cellnumber").Select" part. The problem is that I don't know how to say, if x = 7 select E7. I know there must be a simple way to do it. I remember from reading something that the & operator joined things, but clearly my guess at the syntax here isn't correct. Thanks for taking your time to help.
    Last edited by gryffin13; 06-29-2011 at 01:46 PM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Help looping until a certain cell value

    Hello gryffin13, please wrap your code in code tags as per rule 3 in the forum rules located here. Once you do that we can help you.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    05-25-2011
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Help looping until a certain cell value

    My apologies, I have fixed that.

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Help looping until a certain cell value

    Alright, first thing is, you should try to avoid using .Select if possible (which is most of the time). Secondly this code
    Please Login or Register  to view this content.
    is wrong in that cellnumber should be outside the quotation marks like
    Please Login or Register  to view this content.
    . Notice the replacement of the colon with the comma. At any rate, try the folling code and let me know how it goes:
    Please Login or Register  to view this content.
    Regards

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Help looping until a certain cell value

    Another thing to note is the fact that a recorded macro will show you some defaults like
    Please Login or Register  to view this content.
    which don't need to be programmed evertyime. What I have provided to you could just as well be done with case statements too but I went with the trusty If ElseIf End If statement.

  6. #6
    Registered User
    Join Date
    05-25-2011
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Help looping until a certain cell value

    Thank you. That worked like a charm

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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