Results 1 to 19 of 19

cell references help needed

Threaded View

  1. #1
    Registered User
    Join Date
    07-05-2011
    Location
    Armidale, Australia
    MS-Off Ver
    Excel 2007
    Posts
    12

    Smile cell references help needed

    Hello
    I am having a problem with the syntax of cell references in two places in an Xcel program.
    Someone may be able to see the problem with the code very quickly.
    Appreciate any code change suggestions.

    1) I am trying to write general code that will handle any number of components (=M).

    Can you see what is wrong with this line of code:
    ActiveCell.Offset(0, 1 + i) = "=Input!R[i]C[-30 - i]"
    as shown below?

    All the ‘commented out code is what the for loops are meant to do and is code that works when I run it specifically for M = 5

    Case 5
    ' headings
        Range("AF8").Select
             
        ActiveCell.FormulaR1C1 = "=Input!R[-1]C[-29]"
        ActiveCell.Offset(0, -1) = "Animal"
        ActiveCell.Offset(0, 1) = "=Input!RC[-30]"
        
        For i = 1 To M - 2
       ActiveCell.Offset(0, 1 + i) = "=Input!R[i]C[-30 - i]"  
    Next i
         
        'ActiveCell.Offset(0, 3) = "=Input!R[2]C[-32]"
        'ActiveCell.Offset(0, 4) = "=Input!R[3]C[-33]"
        'ActiveCell.Offset(0, 5) = "=Input!R[4]C[-34]"
        
        ActiveCell.Offset(0, 15) = "Total"
        ActiveCell.Offset(0, 16) = "=RC[-17]"
        ActiveCell.Offset(0, 17) = "=RC[-17]"
        ActiveCell.Offset(0, 18) = "=RC[-17]"
        
        For i = 1 To M - 2
        ActiveCell.Offset(0, 18 + i) = "=RC[-17]"
        
        'ActiveCell.Offset(0, 20) = "=RC[-17]"
        'ActiveCell.Offset(0, 21) = "=RC[-17]"
        'ActiveCell.Offset(0, 22) = "=RC[-17]"
        Next i
        
        ActiveCell.Offset(0, 23) = "=RC[-17]"
        ActiveCell.Offset(0, 32) = "=RC[-17]"
        ActiveCell.Offset(0, 33) = "=RC[-17]"
        ActiveCell.Offset(0, 34) = "=RC[-17]"
        ActiveCell.Offset(0, 35) = "=RC[-17]"
        
        For i = 1 To M - 2
        ActiveCell.Offset(0, 35 + i) = "=RC[-17]"
        
        'ActiveCell.Offset(0, 37) = "=RC[-17]"
        'ActiveCell.Offset(0, 38) = "=RC[-17]"
        'ActiveCell.Offset(0, 39) = "=RC[-17]"
        Next i
               
        ActiveCell.Offset(0, 49) = "=RC[-17]"
        ActiveCell.Offset(0, 51) = "Digestibility"
        ActiveCell.Offset(0, 52) = "Faecal output (kg)"
            
        'values
        Range("BO9").Offset(0, M - 2).Select
            
        Do While IsEmpty(ActiveCell.Offset(0, -34 - M)) = False
        'CSM kg
            
        ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-34 - M],CSMlist,5)"
        'total
        ActiveCell.Offset(0, -18 - M) = "=SUM(RC[-15]:RC[-16 + M])"
       
       ' proportions
        ActiveCell.Offset(0, -17 - M) = "=RC[-17]"
        
        For i = 1 To M
        ActiveCell.Offset(0, -16 - i) = "=RC[-17]/RC47"
        Next i
        
        'ActiveCell.Offset(0, -21) = "=RC[-17]/RC47"
        'ActiveCell.Offset(0, -20) = "=RC[-17]/RC47"
             
        ActiveCell.Offset(0, -1 - M) = "=SUM(RC[-15]:RC[-1])"
        ActiveCell.Offset(0, -M) = "=RC[-17]"
        
        'kg
        For i = 1 To M - 1
        ActiveCell.Offset(0, i - M) = "=RC[-17]*RC[65+M]/RC[48+M]"
        Next i
       
        'ActiveCell.Offset(0, -4) = "=RC[-17]*RC71/RC54"
        'ActiveCell.Offset(0, -3) = "=RC[-17]*RC71/RC54"
        'ActiveCell.Offset(0, -2) = "=RC[-17]*RC71/RC54"
        'ActiveCell.Offset(0, -1) = "=RC[-17]*RC71/RC54"
        
        ActiveCell.Offset(0, 16 - M) = "=SUM(RC[-15]:RC[-1])"
        
            'digest
        ActiveCell.Offset(0, 18 - M) = "=(RC[-36]-1)/RC[-36]"
        ActiveCell.Offset(0, 19 - M) = "=RC[-3]*(1-RC[-1])"
        ActiveCell.Offset(1, 0).Select
        Loop
        
        
     ' hide unused columns
        Range(R8C32 + M, R8C44).Select
        Selection.EntireColumn.Hidden = True
        Range(R8C49 + M, R8C63).Select
        Selection.EntireColumn.Hidden = True
        Range(R8C66 + M, R8C80).Select
        Selection.EntireColumn.Hidden = True

    2) I cannot get
    Pred = Pred + Solver!RC" & 31 + i & " * "Input!R" & 6 + i & "C[2]"
    to work below.

    Again the ‘commented out code that it is designed to replace, works

    Case 5
    ' 5 plant components
        
       Range("B9").Select
            
        Do While IsEmpty(ActiveCell.Offset(0, -1)) = False
        
        If n = 4 Then
        
        Pred = 0
    
    For i = 1 To M
    
    Pred = Pred + Solver!RC" & 31 + i & " * "Input!R" & 6 + i & "C[2]"
    Next i
        
        For j = 1 To 13
        
    '    ActiveCell.FormulaR1C1 = _
            "=((Input!R[22]C[2]/Input!R24C[2]-(Solver!RC32*Input!R7C[2]+Solver!RC33*Input!R8C[2]+Solver!RC34*Input!R9C[2]+Solver!RC35*Input!R10C[2]+Solver!RC36*Input!R11C[2]))^2)"
         
     '   ActiveCell.Offset(0, j) = _
            "=((Input!R[22]C[2]/Input!R24C[2]-(Solver!RC32*Input!R7C[2]+Solver!RC33*Input!R8C[2]+Solver!RC34*Input!R9C[2]+Solver!RC35*Input!R10C[2]+Solver!RC36*Input!R11C[2]))^2)"
        
      '  Next j
        
        ActiveCell.FormulaR1C1 = _
            "=(1*(Input!R[22]C[2]/Input!R24C[2]-Pred))^2)"
        
        ActiveCell.Offset(0, j) = _
            "=(1*(Input!R[22]C[2]/Input!R24C[2]-Pred))^2)"
        
        Next j
    I’ve tried different coding w/o success.

    Last edited by DaveCott; 07-13-2011 at 02:59 AM. Reason: typos

Thread Information

Users Browsing this Thread

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

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