Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default ??? "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*******
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default ??? "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






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default ??? "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








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
How do I add times that were creted with "=TEXT(A2-A1,"h:mm")"? Jaclyn Excel Worksheet Functions 3 December 29th 05 05:31 PM
transpose the code from "rows" to "columns" markx Excel Programming 4 September 21st 05 09:27 AM
Can you "duplicate" "copy" listboxes and code to multiple cells? HotRod Excel Programming 1 September 1st 04 05:03 PM
Looking for VB code to test for "RING" , "BUSY" disconnects or other signals BruceJ[_2_] Excel Programming 3 November 20th 03 01:55 AM


All times are GMT +1. The time now is 11:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"