Results 1 to 6 of 6

Thread: How To Shorten Superfluous Code From Recorded Macro

  1. #1

  2. #2
    Member
    Join Date
    Jun 2013
    Posts
    93
    Rep Power
    11
    Code:
    Sub Macro1()
        Range("E4:N23").Select
        Selection.Borders.LineStyle = xlContinuous
    
    End Sub

  3. #3
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Don't need to write 'Select'

    Code:
    Range("E4:N23").Borders.LineStyle = xlContinuous
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  4. #4
    Member
    Join Date
    May 2013
    Posts
    31
    Rep Power
    0
    To go beyond the recorder: Beyond Excel's recorder

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Rep Power
    0
    Thanks for the help

    I used the recorder and deleted much of the code....i attached workbook....could this be made even simpler?

    Regards

    RK
    Attached Files Attached Files

  6. #6
    Member
    Join Date
    May 2013
    Posts
    31
    Rep Power
    0
    The fewer times that you reference an object the better. This is easy to read anyway.
    Code:
    Private Sub CommandButton2_Click()
      With Range("E4:N4")
        .Interior.ColorIndex = 3
        .Font.Bold = True
        .Font.Size = 16
        .Font.Color = rgbWhite
        .FormulaR1C1 = "=RC[-1]+1"
      End With
      Range("E4").FormulaR1C1 = "=TODAY()"
      Range("E4:N23").Borders.LineStyle = xlContinuous
      Columns("E:N").ColumnWidth = 17.14
    End Sub

Similar Threads

  1. MACRO CODE TO KNOW MONTH and QUATER
    By Prabhu in forum Excel Help
    Replies: 4
    Last Post: 09-27-2013, 10:16 PM
  2. Replies: 1
    Last Post: 08-23-2013, 06:33 PM
  3. Shorten VBA Code By Removing Redundant Superfluous Code
    By paul_pearson in forum Excel Help
    Replies: 2
    Last Post: 08-15-2013, 09:09 PM
  4. Replies: 0
    Last Post: 07-24-2013, 11:20 PM

Posting Permissions

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