Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with "double" loop!


Hi,

I would like to make a loop that fills a cell with a formul
vertically(column index), and then when it reaches the max boundary fo
i(Last specified cell in i) it should 'jump' down a row and begin at th
same column as before. This should be repeated until j(or row index) i
max.
I was thinking something like:

For j = 1 to x
..........
For i = 1 to y
....................
Next i
...........
Next j

However i can't get this to work. Any help will be really appreciated

--
erikh
-----------------------------------------------------------------------
erikhs's Profile: http://www.excelforum.com/member.php...fo&userid=3278
View this thread: http://www.excelforum.com/showthread.php?threadid=56509

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Help with "double" loop!

Cant really see anything wrong with your logic here. Try this example:

Sub loops()

Dim x As Integer
Dim y As Integer

For x = 1 To 10
For y = 1 To 10
Cells(x, y).Value = x & ", " & y
Next y
Next x

End Sub

"erikhs" wrote in
message ...

Hi,

I would like to make a loop that fills a cell with a formula
vertically(column index), and then when it reaches the max boundary for
i(Last specified cell in i) it should 'jump' down a row and begin at the
same column as before. This should be repeated until j(or row index) is
max.
I was thinking something like:

For j = 1 to x
.........
For i = 1 to y
...................
Next i
..........
Next j

However i can't get this to work. Any help will be really appreciated.


--
erikhs
------------------------------------------------------------------------
erikhs's Profile:
http://www.excelforum.com/member.php...o&userid=32788
View this thread: http://www.excelforum.com/showthread...hreadid=565095



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Help with "double" loop!

Hello,

This should do it. (I always prefer to name variables with meaningful names
rather than single letters, otherwise I would I have used i,j etc)

Sub addBlocksofData()

Dim blocks As Integer
Dim off As Integer
Dim blockCounter As Integer
Dim formulaCounter As Integer
Dim nbrFormula As Integer

blocks = 5
nbrFormula = 6
Range("A1").Select
For blockCounter = 1 To blocks
For formulaCounter = 1 To nbrFormula
Selection.Offset(off, 0).Value = "Formula " & Str(formulaCounter)
off = off + 1
Next formulaCounter
Selection.Offset(off, 0) = "" ' Blank
off = off + 1
Next blockCounter

End Sub

ChasAA

"erikhs" wrote:


Hi,

I would like to make a loop that fills a cell with a formula
vertically(column index), and then when it reaches the max boundary for
i(Last specified cell in i) it should 'jump' down a row and begin at the
same column as before. This should be repeated until j(or row index) is
max.
I was thinking something like:

For j = 1 to x
..........
For i = 1 to y
....................
Next i
...........
Next j

However i can't get this to work. Any help will be really appreciated.


--
erikhs
------------------------------------------------------------------------
erikhs's Profile: http://www.excelforum.com/member.php...o&userid=32788
View this thread: http://www.excelforum.com/showthread...hreadid=565095


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 107
Default Help with "double" loop!

try this
dim rng as range
set rng=activesheet.usedrange
for n= 1 to rng.rows.count
for j= 1 to rng.columns.count
cells(n,j)="=formula"'<-------change
next j
next n

--
hemu


"ChasAA" wrote:

Hello,

This should do it. (I always prefer to name variables with meaningful names
rather than single letters, otherwise I would I have used i,j etc)

Sub addBlocksofData()

Dim blocks As Integer
Dim off As Integer
Dim blockCounter As Integer
Dim formulaCounter As Integer
Dim nbrFormula As Integer

blocks = 5
nbrFormula = 6
Range("A1").Select
For blockCounter = 1 To blocks
For formulaCounter = 1 To nbrFormula
Selection.Offset(off, 0).Value = "Formula " & Str(formulaCounter)
off = off + 1
Next formulaCounter
Selection.Offset(off, 0) = "" ' Blank
off = off + 1
Next blockCounter

End Sub

ChasAA

"erikhs" wrote:


Hi,

I would like to make a loop that fills a cell with a formula
vertically(column index), and then when it reaches the max boundary for
i(Last specified cell in i) it should 'jump' down a row and begin at the
same column as before. This should be repeated until j(or row index) is
max.
I was thinking something like:

For j = 1 to x
..........
For i = 1 to y
....................
Next i
...........
Next j

However i can't get this to work. Any help will be really appreciated.


--
erikhs
------------------------------------------------------------------------
erikhs's Profile: http://www.excelforum.com/member.php...o&userid=32788
View this thread: http://www.excelforum.com/showthread...hreadid=565095


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Help with "double" loop!

Erikhs,
I think I misunderstood what you were trying to do but you did say you would
like to fill vertically not horizontally

ChasAA

"erikhs" wrote:


Hi,

I would like to make a loop that fills a cell with a formula
vertically(column index), and then when it reaches the max boundary for
i(Last specified cell in i) it should 'jump' down a row and begin at the
same column as before. This should be repeated until j(or row index) is
max.
I was thinking something like:

For j = 1 to x
..........
For i = 1 to y
....................
Next i
...........
Next j

However i can't get this to work. Any help will be really appreciated.


--
erikhs
------------------------------------------------------------------------
erikhs's Profile: http://www.excelforum.com/member.php...o&userid=32788
View this thread: http://www.excelforum.com/showthread...hreadid=565095


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
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
LOOP BETWEEN "FRONT" AND "END" SHEETS? ewan7279 Excel Programming 7 March 17th 05 03:11 PM


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

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

About Us

"It's about Microsoft Excel"