Microsoft Office Forums vba for next loop

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-31-2018, 11:11 PM
phoenixmoto phoenixmoto is offline vba for next loop Windows 7 64bit vba for next loop Office 2007
Banned
vba for next loop
 
Join Date: Jul 2018
Posts: 11
phoenixmoto is on a distinguished road
Question vba for next loop


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.
Reply With Quote
  #2  
Old 10-31-2018, 11:19 PM
Guessed's Avatar
Guessed Guessed is online now vba for next loop Windows 10 vba for next loop Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,167
Guessed has a spectacular aura aboutGuessed has a spectacular aura aboutGuessed has a spectacular aura about
Default

All the values get written into the same cell and the macro runs so fast you don't see anything until it has completed.

If you want to write to different cells change the location for each value of A
eg.
cells (num,1) = A
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 10-31-2018, 11:34 PM
phoenixmoto phoenixmoto is offline vba for next loop Windows 7 64bit vba for next loop Office 2007
Banned
vba for next loop
 
Join Date: Jul 2018
Posts: 11
phoenixmoto is on a distinguished road
Default

cant we display those answers in a single cell one at a time ?
Reply With Quote
  #4  
Old 11-01-2018, 05:16 AM
Charles Kenyon Charles Kenyon is offline vba for next loop Windows 10 vba for next loop Office 2016
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 5,863
Charles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to allCharles Kenyon is a name known to all
Default

Try:

Code:
sub mac1()
     Dim num as integer
    For num = 1 to 50
       A = num * 2
       cells (1,1) = A
      MsgBox "The current values are " & num & " and " & A
  Next num
end sub
Reply With Quote
  #5  
Old 11-06-2018, 01:59 PM
macropod's Avatar
macropod macropod is online now vba for next loop Windows 7 64bit vba for next loop Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,480
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Cross-posted at: http://www.vbaexpress.com/forum/show...-for-next-loop
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Tags
for next loop, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
vba for next loop Do Loop bug donlincolnmsof Word VBA 11 09-07-2017 10:07 PM
vba for next loop Macro Loop Help Twizzle008 Word VBA 17 09-18-2015 03:20 PM
vba for next loop Loop - Row increment jrt Excel Programming 1 04-16-2015 01:46 PM
vba for next loop End or alter a loop? DJSOUND Word VBA 1 10-11-2013 08:11 PM
vba for next loop How to a For loop in VBA Jennifer Murphy Word VBA 1 01-29-2013 03:30 AM


All times are GMT -7. The time now is 04:11 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Search Engine Optimisation provided by DragonByte SEO v2.0.37 (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft