+ Reply to Thread
Results 1 to 13 of 13

For Loop with Condition on the Pattern of a Cell

  1. #1
    Registered User
    Join Date
    07-19-2013
    Location
    Paris
    MS-Off Ver
    Excel 2010
    Posts
    9

    For Loop with Condition on the Pattern of a Cell

    Hi all,

    New to Macros and VBA.
    I want to run a loop macro down a column (column 6) and check if the cell is hashed out (pattern 2) or not.
    If it is hashed, I want it to enter "-" in the adjacent cell to the right (column 7) and if it isn't I want to copy the text from the unhashed cell (column 6) to the adjacent cell to the right (column 7).

    Thanks in advance for any and all help.

    George

    Please Login or Register  to view this content.
    Last edited by georgesj; 07-23-2013 at 03:04 AM. Reason: Solved

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: For Loop with Condition on the Pattern of a Cell

    George,
    What is not working?

  3. #3
    Registered User
    Join Date
    07-19-2013
    Location
    Paris
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: For Loop with Condition on the Pattern of a Cell

    Currently, I am getting a 438 run time error.

    I have read some tutorials and have lifted most of the code from books so I am really not sure why this is not working.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: For Loop with Condition on the Pattern of a Cell

    Okay!
    In which line do you see the error? Which line is highlighted in yellow?
    I suspect it could be this line

    Please Login or Register  to view this content.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: For Loop with Condition on the Pattern of a Cell

    perhaps
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  6. #6
    Registered User
    Join Date
    07-19-2013
    Location
    Paris
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: For Loop with Condition on the Pattern of a Cell

    Hi thanks AB33 and JosephP; that was the error line and the addition of Interior worked.

    Unfortunately the if loop is not correct now and it just outputs the result of the 'else' for all cells. Any thoughts please?

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: For Loop with Condition on the Pattern of a Cell

    perhaps the pattern is not #2 (which is the third pattern from the left in the dialog) or it is applied by conditional formatting?

  8. #8
    Registered User
    Join Date
    07-19-2013
    Location
    Paris
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: For Loop with Condition on the Pattern of a Cell

    An example of the code which dictates what the pattern is is below:

    Please Login or Register  to view this content.

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: For Loop with Condition on the Pattern of a Cell

    please post a workbook

  10. #10
    Registered User
    Join Date
    07-19-2013
    Location
    Paris
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: For Loop with Condition on the Pattern of a Cell

    I can't post the workbook because it has other people's work in it.

    However, I have made a replica extract in the attached Test Doc.

    Essentially, the LHS column has names that are either unavailable (filled with Hashing Pattern 2) or available (Pattern 0). In the RHS column the names of the individuals should only transfer over if the cell is clear, otherwise I would like to enter a "-" or leave it blank. Currently when the command button is activated every name transfers.

    Thanks

    Test_Doc.xls

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: For Loop with Condition on the Pattern of a Cell

    it seems 2 is not a valid pattern value-you actually get -4125 set so use
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    07-19-2013
    Location
    Paris
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: For Loop with Condition on the Pattern of a Cell

    How strange... I am still using pattern = 2 to set but must use patter = -4125 to recognise it.

    Anyway, thank you kindly for your help on this! Perfectly solved!

  13. #13
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: For Loop with Condition on the Pattern of a Cell

    you're welcome :-)

    please don't forget to mark the thread solved (click the 'thread tools' link at the top, then 'mark solved')

    by the way you can also-and should really-use -4125 to set the pattern

+ 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. Can you change the order/pattern that vba uses to loop through a range?
    By Leon V (AW) in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-14-2013, 04:40 AM
  2. [SOLVED] Loop to change a cell until a condition is met
    By stephen11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2012, 07:34 AM
  3. condition format same value pattern become red
    By choy96 in forum Excel General
    Replies: 1
    Last Post: 11-28-2010, 05:51 AM
  4. Replies: 2
    Last Post: 07-27-2009, 09:29 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