+ Reply to Thread
Results 1 to 18 of 18

For - Array starts at end of count??

  1. #1
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    For - Array starts at end of count??

    Here is a snippet, but I have:

    Please Login or Register  to view this content.
    When executed, C starts off at 20??

    But when I change the code to:

    Please Login or Register  to view this content.
    C starts off at 1?? What the hell?

    This isn't a major issue as I am running a simple script, but I just found it odd. Also, I didn't declare C as any type of variable. Again, not a major issue, but any help/suggestions would be great future references! Thanks.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: For - Array starts at end of count??

    You have almost certainly made some kind of mistake. This just doesn't happen. How do you know the initial value of c? Can you post all your code?

    If you did not declare c it will default to Variant. Because the range is 1 to 20 it will take on an Integer data type.

    I strongly recommend to everyone that they declare variables. Doing so prevents a lot of bug and runtime errors.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

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

    Re: For - Array starts at end of count??

    Can you post the rest of the code?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: For - Array starts at end of count??

    Apologies for the messy code. The whole reasoning of what this code is suppose to do is not important enough to make a super thorough code.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: For - Array starts at end of count??

    Also to notate, variables I used, like "C", in the past; I haven't declared them as variables, but made sure to assign zero to it so i has a integer start point, but I have never come across this issue before doing the same thing.

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

    Re: For - Array starts at end of count??

    How/when are you checking the value of c?

  7. #7
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: For - Array starts at end of count??

    right after dimming everything.
    Please Login or Register  to view this content.
    I begin the variable here, but I update it in:

    Please Login or Register  to view this content.
    I am sure this is due to not declaring c as any type, but its still very odd since i've always used it as a quick get around for a simple quick macro and it has never come close to issues like this.

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

    Re: For - Array starts at end of count??

    I'm sorry but I'm a bit confused, you check the value of c here and the value is 20?
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: For - Array starts at end of count??

    C starts off at 0 so when 'for c = 1 to 20' hits, its recognizes c as 0 rather than empty. But I only did that to see if C would start off at 1 when the command line hit. Didn't change anything until I put 'for c = 1 to 21'. Sorry if I am not understanding what you are asking.

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

    Re: For - Array starts at end of count??

    What exactly do you mean here?
    Please Login or Register  to view this content.
    What happens if you add a simple message box after the for statement?
    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: For - Array starts at end of count??

    If you don't declare it then you can never feel confident in the results. Declare it with Dim c as Integer and see if it's fixed. If not then you can at least rule that out.


    Shelton A.
    If Helpful, Add Reputaion!

  12. #12
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: For - Array starts at end of count??

    I was going to send a screenshot, but now for some reason, I cannot replicate the issue. Even with removing c = 0 from the beginning. I don't know what the hell happen or is going on, but I've come across issues similar to this a time or two. I would like to leave this thread as unsolved so when/if I encounter it again, I can upload a screenshot and continue on this post/thread. If not, I will mark it as solved. I apologize I wasn't more informative, but if ever it occurs again, I will probably just upload the whole xlsm file.

  13. #13
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: For - Array starts at end of count??

    Quote Originally Posted by playaller View Post
    If you don't declare it then you can never feel confident in the results. Declare it with Dim c as Integer and see if it's fixed. If not then you can at least rule that out.
    I have definitely learned quick that its worth taking the time to declare any variables even in the most simplest of macros. But I will continue to try and replicate this issue even if it means not declaring the variable. I am dying to know what was going on.

  14. #14
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: For - Array starts at end of count??

    We'll anxiously await further evidence. In the meantime, let me try to clarify what we all keep asking:

    When executed, C starts off at 20??
    What are you seeing and exactly at what point in execution are you seeing it that leads you to believe that c starts off at 20?

    The only times you use c in this loop, you are subtracting from r. I suspect that the issue is related to r and not c.

  15. #15
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: For - Array starts at end of count??

    Quote Originally Posted by 6StringJazzer View Post
    We'll anxiously await further evidence. In the meantime, let me try to clarify what we all keep asking:



    What are you seeing and exactly at what point in execution are you seeing it that leads you to believe that c starts off at 20?

    The only times you use c in this loop, you are subtracting from r. I suspect that the issue is related to r and not c.
    Ill debug the code line by line using F8. When I get to 'for c = 1 to 20'; If i hover the cursor over C, C shows as zero. If i debug one more line and hover over c once again, then c = 20. C never gets to 'next c' to change c to 2. Hope that is more descriptive.

  16. #16
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: For - Array starts at end of count??

    That is very descriptive, although I have never seen anything like that occur in 15 years of writing VBA. If you are able to replicate, let us know.

  17. #17
    Registered User
    Join Date
    03-15-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    63

    Re: For - Array starts at end of count??

    I'm going to be doing my best trying to replicate this for the remainder of the week. I will keep everyone posted.

  18. #18
    Registered User
    Join Date
    01-17-2012
    Location
    haiti
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: For - Array starts at end of count??

    Quote Originally Posted by schulzy175 View Post
    I'm going to be doing my best trying to replicate this for the remainder of the week. I will keep everyone posted.
    Hi
    i am not a expert but i am had many things like this.
    try put c=0 after "Next C" and if not workts try Before "Next C". Try c=0 at final of code instead top of code. Look in red color.
    remenber eliminate the c=0 of top of code before put at final of code.

    After:
    Please Login or Register  to view this content.
    or try Before:
    Please Login or Register  to view this content.
    Last edited by doriangrey; 01-30-2018 at 10:08 PM.

+ 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] Countif help. Count starts but not finished
    By morerockin in forum Excel General
    Replies: 3
    Last Post: 02-04-2017, 04:33 PM
  2. find count if column has values that starts with certain texts
    By linok in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2015, 11:58 PM
  3. [SOLVED] Finding the lowest value in an array where the values starts in an acsending order.
    By lifeankit in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-29-2013, 03:14 AM
  4. Replies: 1
    Last Post: 05-17-2013, 04:56 AM
  5. Count if based on what cell starts with
    By Staci in forum Excel General
    Replies: 2
    Last Post: 03-26-2011, 08:32 AM
  6. Count down time and count up timer does not starts in another sheet(s)
    By marc5354 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-03-2010, 06:08 PM
  7. Count down time and count up timer does not starts in another sheet(s)
    By marc5354 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-01-2010, 07:52 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