PDA

View Full Version : vba for next loop



phoenixmoto
10-31-2018, 11:35 PM
Dim num as integer
sub mac1()
For num = 1 to 50
A = num * 2
cells (1,1) = A
next num
end sub

If i run this code cell cell(1,1) displays 100 i.e 50 * 2 instead of lowest num no i.e 1 * 2 which is equal to 2. Even if i declare A as integer problem persists please help.

Aussiebear
11-01-2018, 01:43 AM
Have you tried "stepping" through the range 1 to 50?

phoenixmoto
11-01-2018, 06:30 AM
No. how to do that ?

Paul_Hossler
11-01-2018, 06:50 AM
It looks like you're replacing the A1 50 times (2, 4, 6, 8, …., 98, 100), and at the end, only the final value (100) is displayed

Example:




Dim num as integer

sub mac1()
For num = 1 to 50
A = num * 2
cells (num,1) = A
next num
end sub

macropod
11-06-2018, 01:59 PM
Cross-posted at: http://www.msofficeforums.com/word-vba/40780-vba-next-loop.html
Please read VBA Express' policy on Cross-Posting in item 3 of the rules: http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3