+ Reply to Thread
Results 1 to 2 of 2

Loop with a loop? or something else..

Hybrid View

  1. #1
    Registered User
    Join Date
    05-31-2007
    Posts
    24

    Loop with a loop? or something else..

    Greetings

    I've previously posted this on another forum, but I hope someone here may have a fresh perspective;

    This is my FINAL obstacle to overcome before I can put this project to bed.

    Using this code;
    Sub TryThisFillerNext() 
    Dim i As Integer,  eName As String,  SaTotal As String 
    
    'set the first part of the cell formula string 
    SaTotal = "=Sum" 
    
    
    'loop through the list of names that created the worksheets 
        For i = 4 To ThisWorkbook.Sheets("MASTER EDIT").Range("C" & Rows.Count).End(xlUp).Row 
        eName = ThisWorkbook.Sheets("MASTER EDIT").Range("C" & i).Value 
            
    'add each eName and cell to the string    
                    SaTotal = SaTotal + "(" & eName & "!$F$3)+" 
                Next i 
    
     'Set the cell Formula 
           With ActiveSheet 
                 .Range("J4") = SaTotal 
            End With 
    End Sub
    I need to loop these 2 sections 12 times, each loop will advance one ROW from row 3 to row 15
    'add each eName and cell to the string    
             SaTotal = SaTotal + "(" & eName & "!$F$3)+" 
            Next i 
    
    
    
    'Set the cell Formula 
           With ActiveSheet 
                 .Range("J4") = SaTotal 
            End With

    The result after Next i is;

    =SUM(Alpha!$B$3)+(Bravo!$B$3)+(Delta!$B$3)+(Echo!$B$3)+(Fox!$B$3)+(Golf!$B$3)

    Base on the names Alpha to Golf listed in COlumn C of Master Edit sheet.

    Now I somehow need to the !$B$3 to become !$B$4 and .Range("J4") to become .Range("J5")

    This repeats 12 times until !$B$15 and .Range("J16")

    Any suggestions?

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    To loop through the code, you could use something like this:
    For j = 3 To 15
        SaTotal = "=SUM"
        For k = 1 To 6
            eName = Cells(k, 3)  'assumes sheet names begin in row 1
            SaTotal = SaTotal + "(" & eName & "!$B$" & j & ")+"
        Next k
    
        Cells(j + 1, 10) = Left(SaTotal, Len(SaTotal) - 1)  'removes the last +
    Next j
    HTH

    Jason

+ Reply to Thread

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