![]() |
??? "For...Next" code only run 17/35 times
I have a "for...Next" code that is supposed to loop 35 times getting value from cell A3-A38 But it only runs from A3-A17 and stop. I have to run the code 3 times with the following modification:- (1) run For x=A3 to A17 (2) run For x=A18 to A30 (3) run For x =A31 to A38 Hope I could have some advice to fix the problem so that I can run the code once. Thanks a million for your time and expert advice :-) Jaylin *****Jaylin Message ended******* |
??? "For...Next" code only run 17/35 times
"Jaylin" wrote in message ... I have a "for...Next" code that is supposed to loop 35 times getting value from cell A3-A38 But it only runs from A3-A17 and stop. I'm surprised it does that! I have to run the code 3 times with the following modification:- (1) run For x=A3 to A17 (2) run For x=A18 to A30 (3) run For x =A31 to A38 Hope I could have some advice to fix the problem so that I can run the code once. Thanks a million for your time and expert advice :-) Jaylin *****Jaylin Message ended******* Try some debug.print lines in your code. Example Sub test() Dim x For x = A3 To A17 Debug.Print A3 Debug.Print A17 Debug.Print x Next x End Sub When I run the above, I see a single zero but it feed three lines. VBA is seeing A3 A17 as null and x as zero. Without knowing what you are trying to achieve, its difficult to give a good answer other than say if you are trying to have your code loop through your spreadsheet, that's not the way to do it. VBA does not recognise cells addresses in the format you use in you question. You might try looking at the following site under the heading 'Arrays'. http://www.puremis.net/excel/tips.shtml This will show you how to pull values from a spreadsheet into an array, how to do a simple modification and put it back. You might also look at "Range property" and "Cells Property" in VBA help and look at the examples. HTH Steve |
??? "For...Next" code only run 17/35 times
try changing your index variables to x, y, and x instead of using x threee
times. "Steve" <No Spam wrote in message ... "Jaylin" wrote in message ... I have a "for...Next" code that is supposed to loop 35 times getting value from cell A3-A38 But it only runs from A3-A17 and stop. I'm surprised it does that! I have to run the code 3 times with the following modification:- (1) run For x=A3 to A17 (2) run For x=A18 to A30 (3) run For x =A31 to A38 Hope I could have some advice to fix the problem so that I can run the code once. Thanks a million for your time and expert advice :-) Jaylin *****Jaylin Message ended******* Try some debug.print lines in your code. Example Sub test() Dim x For x = A3 To A17 Debug.Print A3 Debug.Print A17 Debug.Print x Next x End Sub When I run the above, I see a single zero but it feed three lines. VBA is seeing A3 A17 as null and x as zero. Without knowing what you are trying to achieve, its difficult to give a good answer other than say if you are trying to have your code loop through your spreadsheet, that's not the way to do it. VBA does not recognise cells addresses in the format you use in you question. You might try looking at the following site under the heading 'Arrays'. http://www.puremis.net/excel/tips.shtml This will show you how to pull values from a spreadsheet into an array, how to do a simple modification and put it back. You might also look at "Range property" and "Cells Property" in VBA help and look at the examples. HTH Steve |
All times are GMT +1. The time now is 08:20 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com