Consulting

Results 1 to 5 of 5

Thread: Combining Code Part Deux

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Combining Code Part Deux

    Thank everybody for all the help reducing my code. It is running much quicker and it is a lot smaller. Here are a few more things I would like to shrink:

    First the same as in the last one: is it possible to combine these two lines where I copy a sheet over and name it at the same time?

    [VBA]
    reOrder.Copy After:=Sheets(1)
    ActiveSheet.Name = "Original"
    [/VBA]

    Next Cut and insert the range in one line:

    [VBA]Columns("A:A").Cut
    Columns("F:F").Insert shift:=xlToRight[/VBA]

    Also many places I do the same formating to multiple columns with a with statement:

    [VBA]With Range("L1", "N1")
    .Value = "Date ______"
    .Font.Bold = True
    .Font.Size = 8
    .WrapText = True
    .Columns.AutoFit
    End With

    With Range("I1", "K1")
    .FormulaR1C1 = "Date ______"
    .Font.Bold = True
    .Font.Size = 8
    .WrapText = True
    .Columns.AutoFit
    End With[/VBA]

    In that last one I know I can select it than run a sub that does the formating but I want to keep the with statement because of speed reasons.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    With regard to Part 3; try using Styles.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    What do you mean Styles?

    Here are a few more:

    [VBA]Range("E" & i).FormulaR1C1 = "=(TODAY()-RC[1])/7"
    Range("E" & i).Value = Range("E" & i).Value[/VBA]


    Also:

    [VBA]Range("J" & i).Offset(-1, 0).FormulaR1C1 = "=RC[-3]-R[1]C[-3]"
    If Abs(Range("J" & i).Offset(-1, 0)) < 0.01 Then Range("J" & i).Offset(-1, 0).ClearContents
    Range("J" & i).Offset(-1, 0).Value = Range("J" & i).Offset(-1, 0).Value[/VBA]

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by Djblois
    What do you mean Styles?
    Format/Style
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Range("E" & i).FormulaR1C1 = "=(TODAY()-RC[1])/7"
    Range("E" & i).Value = Range("E" & i).Value [/VBA]
    or

    [VBA]Range("E" & i) = Format(Date - Range("D" & i) / 7, "dd/mm/yy")[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •