Results 1 to 11 of 11

For loop and change a variable

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-22-2011
    Location
    Texas, United States
    MS-Off Ver
    Excel 2007 and 2010
    Posts
    516

    For loop and change a variable

    Hi All,

    I have this for loop
    For i = 2 To SheetNumber
        If Sheets(i).Range("X2") = 2 Then
            Dog = Dog + (Sheets(i).Range("F10").Value - Sheets(i).Range("B9").Value)
            Counter = Counter + 1
        End If
    Next
    sheets(1).range("B11").value = Dog
    I am wondering if there was a way to change the variable Dog each time in the loop. I think i should be able to do this with an array but i cannot seem to get it. I believe my new code would look something like this.

    Arr = Array("Dog","Cat","Mouse")
    for j = LBound(Arr) to UBound(Arr)
    For i = 2 To SheetNumber
        If Sheets(i).Range("X2") = 2 Then
            j = j + (Sheets(i).Range("F10").Value - Sheets(i).Range("B9").Value)
            Counter = Counter + 1
        End If
    Next
    Next
    sheets(1).range("B11").value = Dog & " Dogs," & Cat & " Cats," & Mouse & " Mice."
    I am not sure if it is something as simple as taking the "" out of the array or what. Is there some way to change a variable each time the for loop is run? Any help is appretiated. Thanks
    Last edited by amotto11; 02-08-2013 at 12:53 PM.

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