Results 1 to 10 of 10

Using for loops when referencing

Threaded View

  1. #1
    Registered User
    Join Date
    08-20-2009
    Location
    Auburn, AL
    MS-Off Ver
    Excel 2003
    Posts
    14

    Smile Using for loops when referencing

    First of all, I'm completely new to both this forum and VBA. I have just done a programming course in java before. I hope you will forgive me if this have already been posted. No to my problem.

    I am tryring to use different projected values to project other subparts of those units, which is done in the sheet mean needed weekly. Tje values are taken from projections. The answer that I get from mean needed weekly should be copied to a third sheet.

    This is the code that I am using right know, but I cant get the for loop to work (or more exactly to be able to place the "i" in my text without making compilation errors).


    Sub Macro3()
    '
    ' Macro3
    ' Macro recorded 8/20/2009 by XXX
    Dim i As Integer
    
    '
    For i = 0 To 51 Step 1
    '
        Sheets("Mean Needed Weekly").Select
        Range("E2").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[2]C[-3]" ' change into b5, b6 (   R[3]C[-3]   )etc. why does not i work?
        Range("E3").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[1]C[-2]"
        Range("E4").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[0]C[-1]"
        Range("E5").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[-1]C"
        Range("E6").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[-2]C[1]"
        Range("E7").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[-3]C[2]"
        Range("E8").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[-4]C[3]"
        Range("E9").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[-5]C[4]"
        Range("E10").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[-6]C[5]"
        Range("E11").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[-7]C[6]"
        Range("E12").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[-8]C[7]"
        Range("E13").Select
        ActiveCell.FormulaR1C1 = "=Projections!R[-9]C[8]"
        Range("E14").Select
        
        Range("M17:M340").Select
        Selection.Copy
        Sheets("Sheet1").Select
        Range((2), (i + 3)).Select ' change to c3, c4 etc. why does not i work?
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        ActiveWindow.SmallScroll Down:=291
        
        Next i
        
     
    
    End Sub
    Thanks in advance!

    E
    Last edited by Operator; 08-21-2009 at 02:06 PM. Reason: Had to insert code tags

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.6.0 RC 1