+ Reply to Thread
Results 1 to 4 of 4

Thread: macro only executes to a specific range and then stops

  1. #1
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    macro only executes to a specific range and then stops

    Hey all,

    I have this macro:
    Sub Justify_Improved()
    '
    ' Justify_Improved Macro
    '
    
    '
        Range("K3").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(RC[-10]=""DF:"",IF(R[1]C[-9]=""Summary Judgement"",RC[-9],""""))"
        Range("K3").Select
        Selection.AutoFill Destination:=Range("K3:K360"), Type:=xlFillDefault
        Range("K3:K360").Select
    
        Range("L3").Select
        ActiveCell.FormulaR1C1 = _
            "=SUBSTITUTE(SUBSTITUTE(RC[-1],"", et al"",""""),"", Et Al"","""")"
        Range("L3").Select
        Selection.AutoFill Destination:=Range("L3:L360")
        Range("L3:L360").Select
        Range("L3:L360").Copy
        Range("M3:M360").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        Range("N3").Select
        ActiveCell.FormulaR1C1 = "=SUBSTITUTE(RC[-1], ""False"", """", 1)"
        Range("N3").Select
        Selection.AutoFill Destination:=Range("N3:N360")
        Range("N3:N360").Select
        Range("N3").Select
        ActiveCell.FormulaR1C1 = "=SUBSTITUTE(RC[-1], ""FALSE"", """", 1)"
        Range("N3").Select
        Selection.AutoFill Destination:=Range("N3:N360")
        Range("N3:N360").Select
    End Sub
    The problem is it executes to a specific range and then stops. So it will stop at row 360, despite the fact that column a can have more rows. Is there a way to get this thing to run the length of column a, where column a has content in its cells?

    Thanks for response.

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,224

    Re: macro only executes to a specific range and then stops

    Like so:

    Option Explicit
    
    Sub Justify_Improved()
    Dim LR As Long
    
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
        Range("K3:K" & LR).FormulaR1C1 = _
            "=IF(RC[-10]=""DF:"",IF(R[1]C[-9]=""Summary Judgement"",RC[-9],""""))"
        
        Range("L3:L" & LR).FormulaR1C1 = _
            "=SUBSTITUTE(SUBSTITUTE(RC[-1],"", et al"",""""),"", Et Al"","""")"
        Range("L3:L" & LR).Copy
        Range("M3").PasteSpecial xlPasteValues
            
        Range("N3:N" & LR).FormulaR1C1 = "=SUBSTITUTE(RC[-1], ""FALSE"", """", 1)"
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    09-19-2010
    Location
    Philadelphia, PA
    MS-Off Ver
    Excel 2007
    Posts
    136

    Re: macro only executes to a specific range and then stops

    Thanks that worked perfect.

  4. #4
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,224

    Re: macro only executes to a specific range and then stops

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

+ Reply to Thread

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.2.0