+ Reply to Thread
Results 1 to 3 of 3

Need help cleaning up code to speed up process...

Hybrid View

  1. #1
    Registered User
    Join Date
    12-02-2012
    Location
    GA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Need help cleaning up code to speed up process...

    Hello all,

    Im new to posting on the forum have been using it to get information to help with coding for quite a while but I need some help on a project I am working on...

    I am trying to clean up my code as I dont do VBA or Macro's very often and need a little help...

    Any suggestions to make it a little lighter or quicker would be great...


    Thanks All in advance...

    Sub Copy_WO_List()
    '
    ' Copy_WO_List Macro
    '
    
        Application.ScreenUpdating = False
        Application.Cursor = xlWait
        Application.DisplayStatusBar = True
        Application.StatusBar = "Updating WO LIST Please Wait..."
        response = MsgBox("Has the Work Order Association file been updated?", vbYesNo)
        If response = vbNo Then Exit Sub
        ActiveWorkbook.Save
        Sheets("DATA").Unprotect
        Sheets("Corridor Status").Unprotect
        Sheets("DATA").Visible = True
        Sheets("DATA").Select
        Workbooks.Open Filename:="L:\Turnover\Status\WO.Association.xlsm"
        Application.Run ("'WO.Association.xlsm'!WorkOrderASSOCIATION")
        Workbooks("WO.Association.xlsm").Close SaveChanges:=True
    ' copy WorkOrder
        
        Sheets("AIRCRAFT STATUS").Activate
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        Dim strName As String
        strName = Range("D8")
        Workbooks.Open Filename:="L:\Turnover\Status\WO.Association.xlsm"
        Sheets(strName).Select
        Range("A1").Select
        Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
        Range("A:C").Select
        Selection.Copy
        Windows("WO_Status.xlsm").Activate
        Sheets("DATA").Select
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        Columns("F:H").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        Workbooks("WO.Association.xlsm").Close SaveChanges:=False
        Range("F1").Value = "ADDS"
        Range("G1").Value = "Corridor Status"
        Range("F2").Select
    ' end copy
    ' DATA Worksheet Move
        Sheets("DATA").Select
        Range("A2:A10000").Select
        Selection.ClearContents
        Range("F2:F10000").Select
        Selection.Copy
        Range("A2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
    'First Run Check and update
        If Range("B2") = "0" Then
            Range("F2:H10000").Select
            Selection.Copy
            Sheets("Corridor Status").Select
            Range("A2").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Application.CutCopyMode = False
        End If
    'End First Run Check and update
    
    'Copy Adds to Status Sheet
        Sheets("DATA").Select
        Range("C2").Select
        Range("C2").AutoFilter Field:=3, Criteria1:="<>"
        Columns("F:H").Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Corridor Status").Select
        Range("A10000").End(xlUp).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=True, Transpose:=False
        Application.CutCopyMode = False
        Sheets("DATA").Select
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        Sheets("Corridor Status").Select
        Range("A2").Select
         Cells.Find(What:="ADDS", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
        Selection.EntireRow.Delete
    'End Copy Adds to Status Sheet
        
        
    'Conditional Formating
        Range("A:A").FormatConditions.Delete
        Range("A2:A10000").Select
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$D2="""""
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 65535
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False
        Range("A2:A10000").Select
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=$B2=""Completed"""
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .Pattern = xlLightHorizontal
            .PatternThemeColor = xlThemeColorDark1
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .PatternTintAndShade = -0.249946592608417
        End With
        Selection.FormatConditions(1).StopIfTrue = True
        Range("A2").Select
        If Worksheets("Corridor Status").FilterMode = False Then
                Selection.AutoFilter
        End If
    'End Conditional Formating
        
    UPDATE1:
    'Update Item status
        Sheets("Corridor Status").Select
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        Range("A1").AutoFilter
        ActiveWorkbook.Worksheets("Corridor Status").AutoFilter.Sort.SortFields.Add _
            Key:=Range("A1:A556"), SortOn:=xlSortOnValues, Order:=xlAscending, _
            DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Corridor Status").AutoFilter.Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        Sheets("DATA").Select
        Range("D2").Select
        Range("A1").AutoFilter
        If ActiveSheet.AutoFilterMode Then
            If ActiveSheet.FilterMode Then
                ActiveSheet.ShowAllData
            End If
        End If
        ActiveSheet.Range("$A$1:$D$10000").AutoFilter Field:=4, Criteria1:="<>0", _
            Operator:=xlAnd, Criteria2:="<>"
        Columns("D:D").Select
        Application.CutCopyMode = False
        Selection.Copy
        Columns("E:E").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        ActiveSheet.Range("$A$1:$D$10000").AutoFilter Field:=4
        Range("E1").Select
        Selection.Delete Shift:=xlUp
        
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        Range("E1:E10000").Select
        Selection.Copy
        Range("F10000").End(xlUp).Offset(1, 0).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        Range("E1:E10000").Select
        Selection.ClearContents
        
        
        Columns("F:H").Select
        Selection.AutoFilter
        If ActiveSheet.AutoFilterMode Then
            If ActiveSheet.FilterMode Then
                ActiveSheet.ShowAllData
            End If
        End If
        ActiveWorkbook.Worksheets("DATA").AutoFilter.Sort.SortFields.Add Key:=Range( _
            "F1:F10001"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("DATA").AutoFilter.Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        Columns("G:G").Select
        Selection.Copy
        Sheets("Corridor Status").Select
        Columns("B:B").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=True, Transpose:=False
        Range("A2").Select
        
    'End update status
    
    'Protect and Hide Data
    Sheets("DATA").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowSorting:=True, AllowFiltering:=True
    Sheets("Corridor Status").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowSorting:=True, AllowFiltering:=True
    Sheets("DATA").Visible = False
    
    'restore default cursor
        Application.Cursor = xlDefault
    'gives control of the statusbar back to the programme
        Application.StatusBar = False
        Application.ScreenUpdating = True
        MsgBox ("Update Complete")
    
    Exit Sub
    Error:
       
    'restore default cursor
    Application.Cursor = xlDefault
    ' gives control of the statusbar back to the programme
    Application.StatusBar = False
    Application.ScreenUpdating = True
    MsgBox "SETUP WO.PDF MACRO"
    MsgBox "WORKBOOK WILL NOW CLOSE"
    ActiveWorkbook.Close False
    End Sub

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Need help cleaning up code to speed up process...

    Sub Copy_WO_List()
    '
    ' Copy_WO_List Macro
    '
    
        Application.ScreenUpdating = False
        Application.Cursor = xlWait
        Application.DisplayStatusBar = True
        Application.StatusBar = "Updating WO LIST Please Wait..."
    
        response = MsgBox("Has the Work Order Association file been updated?", vbYesNo)
    
        If response = vbNo Then Exit Sub
        ActiveWorkbook.Save
        Sheets("DATA").Unprotect
        Sheets("Corridor Status").Unprotect
        Sheets("DATA").Visible = True
        Sheets("DATA").Select
        Workbooks.Open Filename:="L:\Turnover\Status\WO.Association.xlsm"
        Application.Run ("'WO.Association.xlsm'!WorkOrderASSOCIATION")
        Workbooks("WO.Association.xlsm").Close SaveChanges:=True
    ' copy WorkOrder
        
        Sheets("AIRCRAFT STATUS").Activate
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        Dim strName As String
        strName = Range("D8")
        Workbooks.Open Filename:="L:\Turnover\Status\WO.Association.xlsm"
        Sheets(strName).Range("A1").Select
        Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
        Range("A:C").Copy
        Windows("WO_Status.xlsm").Activate
        Sheets("DATA").Select
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        Columns("F:H").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        Workbooks("WO.Association.xlsm").Close SaveChanges:=False
        Range("F1").Value = "ADDS"
        Range("G1").Value = "Corridor Status"
        Range("F2").Select
    ' end copy
    ' DATA Worksheet Move
        Sheets("DATA"). Range("A2:A10000").ClearContents
        Range("F2:F10000").Copy Range("A2")
        
    
    'First Run Check and update
        If Range("B2") = "0" Then
            Range("F2:H10000").Copy Destination:- Sheets("Corridor Status"). Range("A2")
        End If
    'End First Run Check and update
    
    'Copy Adds to Status Sheet
        Sheets("DATA").Range("C2").Select
        Range("C2").AutoFilter Field:=3, Criteria1:="<>"
        Columns("F:H").Copy Destination:=   Sheets("Corridor Status").Range("A10000").End(xlUp).Offset(1, 0)
    
        Sheets("DATA").Select
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        Sheets("Corridor Status").Range("A2").Select
         Cells.Find(What:="ADDS", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
        Selection.EntireRow.Delete
    'End Copy Adds to Status Sheet
        
        
    'Conditional Formating
        Range("A:A").FormatConditions.Delete
        Range("A2:A10000").Select
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$D2="""""
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 65535
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False
        Range("A2:A10000").Select
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=$B2=""Completed"""
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .Pattern = xlLightHorizontal
            .PatternThemeColor = xlThemeColorDark1
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
            .PatternTintAndShade = -0.249946592608417
        End With
        Selection.FormatConditions(1).StopIfTrue = True
        Range("A2").Select
        If Worksheets("Corridor Status").FilterMode = False Then
                Selection.AutoFilter
        End If
    'End Conditional Formating
        
    UPDATE1:
    'Update Item status
        Sheets("Corridor Status").Select
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        Range("A1").AutoFilter
        ActiveWorkbook.Worksheets("Corridor Status").AutoFilter.Sort.SortFields.Add _
            Key:=Range("A1:A556"), SortOn:=xlSortOnValues, Order:=xlAscending, _
            DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Corridor Status").AutoFilter.Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        Sheets("DATA").Range("D2").Select
        Range("A1").AutoFilter
        If ActiveSheet.AutoFilterMode Then
            If ActiveSheet.FilterMode Then
                ActiveSheet.ShowAllData
            End If
        End If
        ActiveSheet.Range("$A$1:$D$10000").AutoFilter Field:=4, Criteria1:="<>0", _
            Operator:=xlAnd, Criteria2:="<>"
        Columns("D:D").Copy Destination:=  Columns("E:E")
    
    ' Or Try  Columns("E:E").value =  Columns("D:D").value
    
        ActiveSheet.Range("$A$1:$D$10000").AutoFilter Field:=4
        Range("E1").Delete Shift:=xlUp
        
        If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
        Range("E1:E10000").Copy Destination:=   Range("F10000").End(xlUp).Offset(1, 0)
        Range("E1:E10000").ClearContents
        
        
        Columns("F:H").Select
        Selection.AutoFilter
        If ActiveSheet.AutoFilterMode Then
            If ActiveSheet.FilterMode Then
                ActiveSheet.ShowAllData
            End If
        End If
        ActiveWorkbook.Worksheets("DATA").AutoFilter.Sort.SortFields.Add Key:=Range( _
            "F1:F10001"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("DATA").AutoFilter.Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
        Columns("G:G").Copy Destination:=  Sheets("Corridor Status").Columns("B:B")
        Range("A2").Select
        
    'End update status
    
    'Protect and Hide Data
    Sheets("DATA").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowSorting:=True, AllowFiltering:=True
    Sheets("Corridor Status").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingCells:=True, AllowSorting:=True, AllowFiltering:=True
    Sheets("DATA").Visible = False
    
    'restore default cursor
        Application.Cursor = xlDefault
    'gives control of the statusbar back to the programme
        Application.StatusBar = False
        Application.ScreenUpdating = True
        MsgBox ("Update Complete")
    
    Exit Sub
    Error:
       
    'restore default cursor
    Application.Cursor = xlDefault
    ' gives control of the statusbar back to the programme
    Application.StatusBar = False
    Application.ScreenUpdating = True
    MsgBox "SETUP WO.PDF MACRO"
    MsgBox "WORKBOOK WILL NOW CLOSE"
    ActiveWorkbook.Close False
    End Sub
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    12-02-2012
    Location
    GA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Need help cleaning up code to speed up process...

    Thanks for the help... Learned a few things here...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Cleaning up and condensing code to speed up process
    By cannedyams in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2012, 11:44 AM
  2. Replies: 5
    Last Post: 03-15-2012, 01:20 AM
  3. Need to speed up process...
    By y34r1ght in forum Excel General
    Replies: 13
    Last Post: 01-10-2007, 06:17 PM
  4. VB code - To Speed up process
    By test1986 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2006, 11:22 AM
  5. [SOLVED] Speed up the process
    By Ali Baba in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 10-03-2005, 02:05 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