+ Reply to Thread
Results 1 to 22 of 22

What's wrong with Range in this For loop

  1. #1
    Registered User
    Join Date
    08-07-2020
    Location
    The Villages Florida
    MS-Off Ver
    2013
    Posts
    21

    What's wrong with Range in this For loop

    It says Compiler error
    Wrong number of Arguments or invalid Property Assignments

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    ]

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: What's wrong with Range in this For loop

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,888

    Re: What's wrong with Range in this For loop

    How about
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: What's wrong with Range in this For loop

    3rd variant
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-07-2020
    Location
    The Villages Florida
    MS-Off Ver
    2013
    Posts
    21

    Re: What's wrong with Range in this For loop

    porucha vevrku

    Your suggestion worked but I was hoping to keep the for loop involved so I don't know how to add the i in the range

    Fluff
    Your suggestion seemed to get lost in the for loop.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,888

    Re: What's wrong with Range in this For loop

    Not quite sure what you mean when you say it got lost in the loop.

  7. #7
    Registered User
    Join Date
    08-07-2020
    Location
    The Villages Florida
    MS-Off Ver
    2013
    Posts
    21

    Re: What's wrong with Range in this For loop

    fluff13
    I had to shut excel down to get out of the Macro
    I don't know if it was the loop or not just seemed like it. Maybe the i got changed from integer to string so the for did not like it.
    If I add a Stop before the Next i it works for 1 loop

    mehmetcik, your suggestion does the same thing

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,888

    Re: What's wrong with Range in this For loop

    What is happening when the data is copied to BN3?

  9. #9
    Registered User
    Join Date
    08-07-2020
    Location
    The Villages Florida
    MS-Off Ver
    2013
    Posts
    21

    Re: What's wrong with Range in this For loop

    fluff13
    On the first loop the data gets there correctly

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,888

    Re: What's wrong with Range in this For loop

    Do you have any event code, that is triggered by copying the data?
    You should not end up in a permanent loop with the code you posted.

  11. #11
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,027

    Re: What's wrong with Range in this For loop

    On the first loop the data gets there correctly
    You are overwriting the data all the time...Each loop is pasting to same cell BN3...?
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  12. #12
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: What's wrong with Range in this For loop

    It seems that the copied cell values (to the 'BN3:BW3' range) ​​from rows of individual columns (i.e.: L.row, Q.row, V.row, AA.row, AF.row, AK.row, AP.row, AU.row, AZ.row, BE.row) are used to create calculations "on the fly" for other purposes/calculations ... (???)

  13. #13
    Registered User
    Join Date
    08-07-2020
    Location
    The Villages Florida
    MS-Off Ver
    2013
    Posts
    21

    Re: What's wrong with Range in this For loop

    fluff13
    To clarify my last reply
    If I have a Stop before Next i the data for the first loop is correct

    If I don't have a Stop then if it runs it goes quickly to about i=12 then it takes about 3 seconds for each i in the loop and BN3 shows the correct value.
    Makes me think it is running out of memory.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,888

    Re: What's wrong with Range in this For loop

    I understand that, but why are you copying it to BN3 every time?

  15. #15
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: What's wrong with Range in this For loop

    Quote Originally Posted by pumper View Post
    it takes about 3 seconds for each i in the loop and BN3 shows the correct value
    Attach some reliable/trustworthy 'xls' file example (data must be false => data privacy and confidentiality protection).

  16. #16
    Registered User
    Join Date
    08-07-2020
    Location
    The Villages Florida
    MS-Off Ver
    2013
    Posts
    21

    Re: What's wrong with Range in this For loop

    When I get it to work, which it may be now if memory is a problem, there will be other code in between so I will put it in my big program to test.
    When all the data gets to BN3 etc I will find the Min value which I can't do when the data is not contiguous.
    That will happen in between each "for i" so overwriting data should not be a problem.

  17. #17
    Registered User
    Join Date
    08-07-2020
    Location
    The Villages Florida
    MS-Off Ver
    2013
    Posts
    21

    Re: What's wrong with Range in this For loop

    porucha vevrku
    Yes I am putting it there so I can find the Min value which I can't do when the data is not in contiguous cells.

  18. #18
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: What's wrong with Range in this For loop

    Min value from the whole "non-contiguous" range, i.e. ranges: L5:L33, Q5:Q33, V5:V33, AA5:AA33, AF5:AF33, AK5:AK33, AP5:AP33, AU5:AU33, AZ5:AZ33, BE5:BE33 (at once) ?
    Or min value for any individual row of "non-contiguous" range (L & row, Q & row, V & row, AA & row, AF & row, AK & row, AP & row, AU & row, AZ & row, BE & row), one by one (29 times) ?

  19. #19
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,888

    Re: What's wrong with Range in this For loop

    If you just want the min value from each row, you can use
    Please Login or Register  to view this content.

  20. #20
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,481

    Re: What's wrong with Range in this For loop

    Quote Originally Posted by Fluff13 View Post
    If you just want the min value from each row, you can use
    Please Login or Register  to view this content.
    You can write the highlighted line of code in a more compact and (slightly) less ugly way (the "i" variable only appears once and there are no concatenations) like this...
    Please Login or Register  to view this content.
    Even more compact and still (slightly) less ugly (again, the "i" variable only appears once and there are still no concatenations) although not as easy to read which columns are involved because you can't see the letter designations)...
    Please Login or Register  to view this content.
    Last edited by Rick Rothstein; 08-30-2020 at 04:44 PM.

  21. #21
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: What's wrong with Range in this For loop

    Variant 1:
    Please Login or Register  to view this content.
    Variant 2:
    Please Login or Register  to view this content.
    Min value for Variant 1 <> Min value for Variant 2.

  22. #22
    Registered User
    Join Date
    08-07-2020
    Location
    The Villages Florida
    MS-Off Ver
    2013
    Posts
    21

    Re: What's wrong with Range in this For loop

    I can't thank all of you enough.
    I don't know if I will ever learn as much as all of you know but I will keep trying.

+ 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] What's wrong with this loop?
    By DMA in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-15-2017, 05:18 AM
  2. Why is my nested countif loop wrong
    By falco008 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2016, 06:07 AM
  3. [SOLVED] Whats wrong with my loop
    By dlow in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2015, 03:45 PM
  4. [SOLVED] Whats wrong with this loop
    By rpinxt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2014, 07:05 AM
  5. What is wrong with this for loop?
    By kmakjop in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-17-2014, 02:31 PM
  6. If Loop Wrong Usage?
    By coconutmango in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2011, 08:11 PM
  7. What's wrong with my loop ?
    By Grek in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-13-2006, 02:23 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