![]() |
Working with a Loop
I can't figure out why this double loop does not work...
For X = 1 To 9 For T = 1 To 11 range("SP[DATE]").Select Selection.Find(What:=CURRPERCENTAGE.Value, After:=ActiveCell, LookIn:=xlValues, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Offset(0, 1).Activate CURRPERCENTAGE.Offset(X, 0) = ActiveCell Set CURRPERCENTAGE = CURRPERCENTAGE.Offset(0, 1) T = T + 1 MsgBox T Next Next If you have any idea, it would be greatly appreciated..I have tried everything... |
Working with a Loop
I see where you increment T .... T = T + 1
But not for X ??? R Tanner wrote: I can't figure out why this double loop does not work... For X = 1 To 9 For T = 1 To 11 range("SP[DATE]").Select Selection.Find(What:=CURRPERCENTAGE.Value, After:=ActiveCell, LookIn:=xlValues, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Offset(0, 1).Activate CURRPERCENTAGE.Offset(X, 0) = ActiveCell Set CURRPERCENTAGE = CURRPERCENTAGE.Offset(0, 1) T = T + 1 MsgBox T Next Next If you have any idea, it would be greatly appreciated..I have tried everything... |
Working with a Loop
Elmtree wrote:
I see where you increment T .... T = T + 1 But not for X ??? R Tanner wrote: I can't figure out why this double loop does not work... For X = 1 To 9 For T = 1 To 11 range("SP[DATE]").Select Selection.Find(What:=CURRPERCENTAGE.Value, After:=ActiveCell, LookIn:=xlValues, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Offset(0, 1).Activate CURRPERCENTAGE.Offset(X, 0) = ActiveCell Set CURRPERCENTAGE = CURRPERCENTAGE.Offset(0, 1) T = T + 1 MsgBox T Next Next If you have any idea, it would be greatly appreciated..I have tried everything... Both T and X are incremented in the for/next loops. The thing that caught my eye is T is also incremented by T = T + 1 /inside/ the T loop. This amounts to evaluating T as 1, 3, 5, etc., although the MsgBox will report 2, 4, 6, etc. I don't know what the OP is trying to do here, but this seems odd to me. |
Working with a Loop
It would have helped if you had told us what "does not work" meant (did you
see an error message, which one, nothing happened, etc.). I do note that you have T=T+1 in your code... perhaps that statement is your problem as it would force T to increment by two on each loop (once for that statement and once more from the For statement itself. Comment that statement out and see if that corrects your problem. -- Rick (MVP - Excel) "R Tanner" wrote in message ... I can't figure out why this double loop does not work... For X = 1 To 9 For T = 1 To 11 range("SP[DATE]").Select Selection.Find(What:=CURRPERCENTAGE.Value, After:=ActiveCell, LookIn:=xlValues, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Offset(0, 1).Activate CURRPERCENTAGE.Offset(X, 0) = ActiveCell Set CURRPERCENTAGE = CURRPERCENTAGE.Offset(0, 1) T = T + 1 MsgBox T Next Next If you have any idea, it would be greatly appreciated..I have tried everything... |
Working with a Loop
I copied the code and tried it myself.
I removed the T = T + 1 line. also removed the code inside the T loop. It increments by 1 now, but when it finishes with T, it repeats the T loop. That may be his problem. Rick Rothstein wrote: It would have helped if you had told us what "does not work" meant (did you see an error message, which one, nothing happened, etc.). I do note that you have T=T+1 in your code... perhaps that statement is your problem as it would force T to increment by two on each loop (once for that statement and once more from the For statement itself. Comment that statement out and see if that corrects your problem. I can't figure out why this double loop does not work... [quoted text clipped - 17 lines] If you have any idea, it would be greatly appreciated..I have tried everything... |
Working with a Loop
Let me clairfy my last statement.
I think it works OK once you take the T = T + 1 line out. What he sees is the T msgbox repeating itself. But what he does not see is the X value. I put in a X msgbox, it loops the T until X = 9, then ends. Maybe this fixed his problem.... Elmtree wrote: I copied the code and tried it myself. I removed the T = T + 1 line. also removed the code inside the T loop. It increments by 1 now, but when it finishes with T, it repeats the T loop. That may be his problem. It would have helped if you had told us what "does not work" meant (did you see an error message, which one, nothing happened, etc.). I do note that you [quoted text clipped - 8 lines] If you have any idea, it would be greatly appreciated..I have tried everything... |
Working with a Loop
I didn't try his code... I just am pretty sure the T=T+1 is not right (if
the OP really needed this, he would simply have to use a Step 2 qualifier on his For statement line). -- Rick (MVP - Excel) "Elmtree" <u45848@uwe wrote in message news:8969c64ac70b5@uwe... I copied the code and tried it myself. I removed the T = T + 1 line. also removed the code inside the T loop. It increments by 1 now, but when it finishes with T, it repeats the T loop. That may be his problem. Rick Rothstein wrote: It would have helped if you had told us what "does not work" meant (did you see an error message, which one, nothing happened, etc.). I do note that you have T=T+1 in your code... perhaps that statement is your problem as it would force T to increment by two on each loop (once for that statement and once more from the For statement itself. Comment that statement out and see if that corrects your problem. I can't figure out why this double loop does not work... [quoted text clipped - 17 lines] If you have any idea, it would be greatly appreciated..I have tried everything... |
Working with a Loop
It may be best to start from the beginning and tell us your layout and what
you want to happen. I can't see T doing anything and selections are not necessary. If desired, send your workbook to my address below along with an explanation and I'll take a look. -- Don Guillett Microsoft MVP Excel SalesAid Software "R Tanner" wrote in message ... I can't figure out why this double loop does not work... For X = 1 To 9 For T = 1 To 11 range("SP[DATE]").Select Selection.Find(What:=CURRPERCENTAGE.Value, After:=ActiveCell, LookIn:=xlValues, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _ MatchCase:=False, SearchFormat:=False).Offset(0, 1).Activate CURRPERCENTAGE.Offset(X, 0) = ActiveCell Set CURRPERCENTAGE = CURRPERCENTAGE.Offset(0, 1) T = T + 1 MsgBox T Next Next If you have any idea, it would be greatly appreciated..I have tried everything... |
All times are GMT +1. The time now is 05:29 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com