+ Reply to Thread
Results 1 to 4 of 4

Thread: an array inside the loop won't work

  1. #1
    Registered User
    Join Date
    12-29-2009
    Location
    brooklyn, ny
    MS-Off Ver
    Excel 2003
    Posts
    13

    an array inside the loop won't work

    I am trying to insert numbers 11 through 18 in the range B2:F2. I almost got it, except that it doesn't work. Can somebody point me on the right track and tell me what am I doing wrong? thank you

    here is my code :
    Private Sub CommandButton1_Click()
    
    Dim intr(2 To 2, 2 To 6) As Single
    Dim row As Integer, col As Integer, nn As Integer
    
           For nn = 11 To 18
           For col = 2 To 2
           For row = 2 To 6
                         
                Cells(col, row).Value = intr(col, row)
                intr(col, row) = nn
    
              Next row
              Next col
          Next nn
          
    End Sub
    Last edited by ilya49; 07-26-2011 at 09:15 PM.

  2. #2
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: an array inside the loop won't work

    Hi ilya49, I am a little confused, sorry. You want to fit 11 to 18 (8 separate numbers) into range B2:F2 (5 columns). The following code will put 11 to 18 into the range B2:I2
    Sub ilya49()
        Dim colNum As Long, rowNum As Long
        colNum = 1
        For nm = 11 To 18
            colNum = colNum + 1
            Sheets(4).Cells(2, colNum).Value = nm
        Next nm
    End Sub
    Is this what you really wanted?
    Please leave a message after the beep!

  3. #3
    Registered User
    Join Date
    12-29-2009
    Location
    brooklyn, ny
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: an array inside the loop won't work

    Thank You

    that's exactly what I needed.

  4. #4
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: an array inside the loop won't work

    You're welcome!
    Please leave a message after the beep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0