Hello, I inherited an Excel file that has a macro. Basically, you are supposed to click a button and it updates from two different files saved in a network drive. The updating works fine, however it is supposed to set a print area and perform a custom sort. The issue I have been asked to fix is: clicking the update button once updates the base data only, and clicking it a second time will set the print area. It does not however, perform the custom sort.
I've tested the macro and made a few changes, but I just can't seem to get the custom sort and set print area to complete with only one click of the button. I know I'm missing something, but my brain just isn't seeing something. Hope someone can help, this is getting frustrating. Thanks
Sub Update()
'
' Update Macro
'
Dim x As Long, y As Long
Dim rngPrintArea As Range
x = Cells(1, Columns.Count).End(xlToLeft).Column
y = Cells(Rows.Count, 1).End(xlUp).Row
Set rngPrintArea = Range(Cells(1, 1), Cells(y, x))
With Application
.ScreenUpdating = False: .DisplayAlerts = False
End With
With Range("A2:I199")
.ClearContents
End With
Range("A2").Select
Sheets("917_Confirm").Select
Selection.ClearContents
Range("A2").Select
Sheets("IQA_48HR").Select
Workbooks.Open Filename:="S:\Mfg_Quality\Daily_Metrics\Temp\LX03_temp.xlsx"
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Windows("IQA_48HR.xlsm").Activate
Range("A2").Select
ActiveSheet.Paste
Sheets("917_Confirm").Select
Windows("LX03_temp.xlsx").Activate
ActiveWindow.Close
Workbooks.Open Filename:="S:\Mfg_Quality\Daily_Metrics\Temp\LT23_temp.xlsx"
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Windows("IQA_48HR.xlsm").Activate
Range("A2").Select
ActiveSheet.Paste
Windows("LT23_temp.xlsx").Activate
ActiveWindow.Close
Sheets("IQA_48HR").Select
Range("T18").Select
ActiveSheet.PageSetup.PrintArea = rngPrintArea.Address
Range("T18").Select
ActiveWorkbook.Save
With Application
.ScreenUpdating = True: .DisplayAlerts = True
End With
End Sub
I've tested the macro and made a few changes, but I just can't seem to get the custom sort and set print area to complete with only one click of the button. I know I'm missing something, but my brain just isn't seeing something. Hope someone can help, this is getting frustrating. Thanks
Sub Update()
'
' Update Macro
'
Dim x As Long, y As Long
Dim rngPrintArea As Range
x = Cells(1, Columns.Count).End(xlToLeft).Column
y = Cells(Rows.Count, 1).End(xlUp).Row
Set rngPrintArea = Range(Cells(1, 1), Cells(y, x))
With Application
.ScreenUpdating = False: .DisplayAlerts = False
End With
With Range("A2:I199")
.ClearContents
End With
Range("A2").Select
Sheets("917_Confirm").Select
Selection.ClearContents
Range("A2").Select
Sheets("IQA_48HR").Select
Workbooks.Open Filename:="S:\Mfg_Quality\Daily_Metrics\Temp\LX03_temp.xlsx"
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Windows("IQA_48HR.xlsm").Activate
Range("A2").Select
ActiveSheet.Paste
Sheets("917_Confirm").Select
Windows("LX03_temp.xlsx").Activate
ActiveWindow.Close
Workbooks.Open Filename:="S:\Mfg_Quality\Daily_Metrics\Temp\LT23_temp.xlsx"
Range("A2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Windows("IQA_48HR.xlsm").Activate
Range("A2").Select
ActiveSheet.Paste
Windows("LT23_temp.xlsx").Activate
ActiveWindow.Close
Sheets("IQA_48HR").Select
Range("T18").Select
ActiveSheet.PageSetup.PrintArea = rngPrintArea.Address
Range("T18").Select
ActiveWorkbook.Save
With Application
.ScreenUpdating = True: .DisplayAlerts = True
End With
End Sub