I am trying to close out of Excel after the Msgbox ok is pressed.
The msg only appears if there is no data. After which I want excel to close out completely.
The msg only appears if there is no data. After which I want excel to close out completely.
VBA Code:
Sub AStart()
'
Application.ScreenUpdating = False ' Added to speed up the process
Sheets("Data").Cells.Clear ' Clear Data WS in case data was accidnetlally left over.
Workbooks.Open Filename:="C:\temp\ReportOutput.xls" ' Opens Access exported Excel file
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy ' Select and copy all the data from ReportOutput.xls
Windows("Report.xlsm").Activate
Sheets("Data").Select
Range("A1").Select
ActiveSheet.Paste ' Activate and Paste data back over to
Application.CutCopyMode = False
'Sheets.Add Before:=ActiveSheet
' This code is being placed so if there is no data to exit any further code and let user no there is no data between that range.
[B]
If Len(Range("A2").Value) = 0 Then
MsgBox "HELLO!. "
Windows("ReportOutput.xls").Activate
ActiveWorkbook.Close
Windows("Report.xlsm").Activate
ActiveWorkbook.Close
SaveChanges = False
Application.Quit[/B]
Exit Sub
End If
Sheets("PivotTable").Select
Application.DisplayAlerts = True
Set PSheet = Worksheets("PivotTable")
Set DSheet = Worksheets("Data")
'Define Data Range
lastRow = DSheet.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = DSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Set PRange = DSheet.Cells(1, 1).Resize(lastRow, LastCol)
'Define Pivot Cache
Set PCache = ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:=PRange). _
CreatePivotTable(TableDestination:=PSheet.Cells(5, 1), _
TableName:="PivotTable2")
Call AMasterBuild2
End Sub