Results 1 to 6 of 6

Add loop to this section of my Macro

Threaded View

  1. #1
    Registered User
    Join Date
    07-26-2012
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    5

    Add loop to this section of my Macro

    hi there -

    I currently have a functioning macro that has a section that finds "s.w." in the contents of a cell in one column (column A) and then pastes a certain formula into the corresponding cell in an adjacent column (column E) . I want this particular part of my macro to loop through till the last row with data in column A or until there are no more "S.W" cell contents.

    This is what I want to loop:



    Dim r As Range
        Set r = ActiveSheet.Range("A11:A500").Find(What:="*S.W.*", LookAt:=xlPart)
        If Not r Is Nothing Then r.Offset(, 4).Formula = "=GL(R7C9,R3C9,RC[-2],R4C9)"


    The full macro looks like this:



    Sub Portfolio2GL()
    'DELETE SW
    Dim x As Integer
         
        With Columns("C:C")
            .Replace What:="sw", Replacement:=""
        End With
    
    'ADD ZERO
    'Declarations
    
    Dim cl As Range
    Dim I As Long, endrow As Long
    
    Application.ScreenUpdating = False
        'Converts the C column format to Text format
        Columns("C:C").NumberFormat = "@"
        'finds the bottom most row
        endrow = ActiveSheet.Range("C500").End(xlUp).Row
        '## Or, for Excel 2003 and prior: ##'
        'endrow = ActiveSheet.Range("C___").End(xlUp).Row
    
        'loop to move from cell to cell
        For I = 11 To endrow - 1
            Set cl = Range("C" & I)
            With cl
            'The Do-While loop keeps adding zeroes to the front of the cell value until it hits a length of 3
                Do While Len(.Value) < 3
                    .Value = "0" & .Value
                Loop
            End With
        Next I
    Application.ScreenUpdating = True
    
    'ADD MAIN FORMULA 
    
    Dim lastRow As Long
       lastRow = Range("D500").End(xlUp).Row - 1
       Range("E11").FormulaR1C1 = "=GL(R6C9,R3C9,RC[-2],R4C9)+GL(R5C9,R3C9,RC[-2],R4C9)"
       Range("E11").AutoFill Destination:=Range("E11:E" & Cells(Rows.Count, 2).End(xlUp).Row)
    
    ' REPLACE MAIN FORMULA with S.W. formula where necessary
    
    Dim r As Range
    
        Set r = ActiveSheet.Range("A11:A500").Find(What:="*S.W.*", LookAt:=xlPart)
        If Not r Is Nothing Then r.Offset(, 4).Formula = "=GL(R7C9,R3C9,RC[-2],R4C9)"
    
    End Sub
    THANKS!
    Last edited by alansidman; 12-02-2013 at 08:13 PM. Reason: code tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 06-16-2013, 07:36 AM
  2. Deleting Row Section without Disrupting Formula Range Outside of Deleted Section
    By JeffNYG23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2013, 09:10 AM
  3. I need a macro that will let me loop a section of the vba code x number of times
    By tuckejam in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-28-2013, 02:44 PM
  4. Moving section headings from below section to above section..
    By Fayebaline in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-24-2011, 06:58 AM
  5. move that Row From the Waiting section to the completed section automaticly
    By jjsaw5 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-21-2007, 06:50 PM

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