+ Reply to Thread
Results 1 to 5 of 5

Optimisation of code

Hybrid View

  1. #1
    Registered User
    Join Date
    11-22-2009
    Location
    Newcastle,England
    MS-Off Ver
    Excel 2003
    Posts
    78

    Optimisation of code

    With Worksheets("highlowperf")
        
        Range("A1").Select
        ActiveCell.Formula = "Team"
        Range("B1").Select
        ActiveCell.Formula = "AO names"
        Range("C1").Select
        ActiveCell.Formula = "AO hours"
        Range("D1").Select
        ActiveCell.Formula = "Week avg % productive time"
        Range("E1").Select
        ActiveCell.Formula = "Week avg % meeting target to PA"
        Range("F1").Select
        ActiveCell.Formula = "High/Low %prod time"
        Range("G1").Select
        ActiveCell.Formula = "High/Low %meeting target to PA"
        Range("H1").Select
        ActiveCell.Formula = "prod time sev"
        Range("I1").Select
        ActiveCell.Formula = "meet pa sev"
        Range("J1").Select
        ActiveCell.Formula = "Total sev"
        Range("K1").Select
        ActiveCell.Formula = "sev rating"
        
    
        
    Application.ScreenUpdating = True
    End With
    I have this as part of a bigger macro. Is there a quicker method to setting the titles to the first row of columns other than having the macro select each cell then add the text as shown?
    Last edited by munkee; 12-18-2009 at 04:02 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    07-21-2008
    Location
    London, UK
    Posts
    326

    Re: Optimisation of code

    Range("A1").Formula = "Team"
    
    Range("B1").Formula = "AO names"

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Optimisation of code

    Try this:
    Sub NewTitles()
        Range("A1") = "Team"
        Range("B1") = "AO names"
        Range("C1") = "AO hours"
        Range("D1") = "Week avg % productive time"
        Range("E1") = "Week avg % meeting target to PA"
        Range("F1") = "High/Low %prod time"
        Range("G1") = "High/Low %meeting target to PA"
        Range("H1") = "prod time sev"
        Range("I1") = "meet pa sev"
        Range("J1") = "Total sev"
        Range("K1") = "sev rating"
    End Sub
    Does that help?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Optimisation of code

    You can store the values in an Array if you find it easier to adapt in that manner, eg:

    Dim vTitles
    vTitles = Array("Team", "AO names", "AO hours", "etc....")
    With Sheets("highlowperf")
        .Cells(1, "A").Resize(, 1 + UBound(vTitles)).Value = vTitles
    End With
    In VBA you rarely need to .Select anything - doing so will slow your code.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Optimisation of code

    Another way
    Option Explicit
    
    Sub NewTitles()
    
        Dim Col    As Long
        Const Rw   As Long = 1
        For Col = Rw To 11
            Cells(Rw, Col).Value = Choose(Col, "Team", "AO names", "AO hours", _
                                          "Week avg % productive time", "Week avg % meeting target to PA", _
                                          "High/Low %prod time", "High/Low %meeting target to PA", "prod time sev", _
                                          "meet pa sev", "Total sev", "sev rating")
        Next Col
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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