+ Reply to Thread
Results 1 to 13 of 13

Loop in Range

  1. #1
    Registered User
    Join Date
    07-27-2016
    Location
    US
    MS-Off Ver
    2013
    Posts
    10

    Loop in Range

    Hello All,

    I am trying to loop numbers in specific range. The code I have so far is not working 100%.
    Please Login or Register  to view this content.
    In some cases, when column number is less than loop number in range, the code does not work. For instance when cell value is "a" for I2, J4, and K5, looping numbers populated out of range. Is it possible to fix this issue. Thanks in advance.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Loop in Range

    What are you trying to do with the code/loop?
    If posting code please use code tags, see here.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Loop in Range

    Oh, and why do you have so many loops?

  4. #4
    Registered User
    Join Date
    07-27-2016
    Location
    US
    MS-Off Ver
    2013
    Posts
    10

    Re: Loop in Range

    I would combine these loops if I have little bit knowledge, I know it looks inefficient. I am trying to get this result
    Please Login or Register  to view this content.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Loop in Range

    To loop through a range you should only really need one loop, probably the For Each from your code.

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.

  6. #6
    Registered User
    Join Date
    07-27-2016
    Location
    US
    MS-Off Ver
    2013
    Posts
    10

    Re: Loop in Range

    Sure. Please see attached file
    Attached Files Attached Files

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Loop in Range

    So you want to loop through H1:P10 an check the cells for 'a', then what...?

  8. #8
    Registered User
    Join Date
    07-27-2016
    Location
    US
    MS-Off Ver
    2013
    Posts
    10

    Re: Loop in Range

    yes, vba code looks for "a" in the range and loop forward and backward right next to "a" cell. But there is a problem about looping it is looping out of the range, I want vba loop in the range H1:P10. with this code it is looping to F and G columns.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Loop in Range

    The For Each loop will loop through H1 to P10 but you never refer to the loop variable Cell anywhere else in the code.

    These loops will go through A1 to O15.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-27-2016
    Location
    US
    MS-Off Ver
    2013
    Posts
    10

    Re: Loop in Range

    yeap make sense that is why the code I put running out of range. So what should I put that works in the specific range.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Loop in Range

    If you want to loop through the range H1:P10 all you need us the For Each you already have in the code.

  12. #12
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    13,035

    Re: Loop in Range

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by protonLeah; 07-28-2016 at 10:27 PM.
    Ben Van Johnson

  13. #13
    Registered User
    Join Date
    07-27-2016
    Location
    US
    MS-Off Ver
    2013
    Posts
    10

    Re: Loop in Range

    Great! it is working , thank you very much for your time.

+ 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. Loop through files in folder, copy range, Paste range to original workbook
    By knevil in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-09-2016, 05:33 PM
  2. Loop through each folder copy values from range in file1 to named range in file2
    By dafella in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-16-2015, 05:19 PM
  3. Loop issues - Find value in range that fits value in defined name range
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-31-2014, 11:33 AM
  4. Replies: 1
    Last Post: 01-23-2013, 03:00 PM
  5. Problem using loop for sending excel range in email body using Range to HTML code
    By drajanm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-24-2012, 03:17 AM
  6. Replies: 3
    Last Post: 06-22-2012, 06:40 PM
  7. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM

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