Consulting

Results 1 to 2 of 2

Thread: Loop question

  1. #1
    VBAX Regular
    Joined
    Jul 2008
    Posts
    12
    Location

    Loop question

    I have a simple VBA code

    For period = 0 to 100 Step 10

    Sheets("sheet1").Select
    Range("A1").Select
    ActiveCell.Formula= period
    Sheets("sheet2").Select
    Range ("B1").Select
    ActiveCell.Formula="=Sheet1R5C5"

    Next period

    End period.

    Basically, I change a variable in sheet1 cell A1 and that creates a new value for the formula output in cell E5. I paste this output in cell B1 on sheet2.

    My question is, how do I work with the loop so that the next value of period in the loop gets posted in cell B2 and not B1 again.

    Thanks a lot for your answer.

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    I think there is an error at[VBA]ActiveCell.Formula="=Sheet1R5C5"[/VBA]

    [VBA]
    Dim RowCnt As Long
    RowCnt = 1
    For Period = 0 To 100 Step 10
    Worksheets("sheet1").Cells(1, 1).Formula = Period
    'Sheets("sheet1").Select
    'Range("A1").Select
    'ActiveCell.Formula = Period
    'row, column
    Worksheets("sheet2").Cells(RowCnt, 2).Formula = "=Sheet1R5C5"
    RowCnt = RowCnt + 1
    'Sheets("sheet2").Select
    'Range("B1").Select
    'ActiveCell.Formula = "=Sheet1R5C5"
    Next Period

    [/VBA]

Posting Permissions

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