here is how it looks now:
Option Explicit
Sub SaveMe()
Dim test1 As Range, test2 As Range
Set test1 = Worksheets("Robert").Range("E1")
Set test2 = Worksheets("Robert").Range("B11")
If test1.Value2 = test2.Value2 Then
MsgBox "You can only update the database once a day!!! If you made a
mistake, message: RompStar"
'MsgBox test1.Value & vbLf & test2.Value
Exit Sub
Else
Call SaveMe2
End If
'rest of code here
' Exit Sub
End Sub
Sub SaveMe2()
Dim MstrWkbk As Workbook
Dim MstrWkbkName As String
Dim CurWkbk As Workbook
Dim SheetNames As Variant
Dim sCtr As Long
Dim testStr As String
Dim okToContinue As Boolean
Dim RngToCopy As Range
Dim DestCell As Range
Dim resp As Long
' Enter file location name, needs to match or else the Cat gets it.
MstrWkbkName = "\\network\location\appendfile.xls"
testStr = ""
On Error Resume Next
testStr = Dir(MstrWkbkName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Master workbook not found! Contact: (e-mail address removed)"
GoTo exitNow:
End If
' Pop a BOX on the screen to warn of double-appends
resp = MsgBox(Prompt:="Please make sure the data is correct before
uploading... Are you sure you want to run this?", _
Buttons:=vbYesNo)
' If user chooses No, then exit script...
If resp = vbNo Then
GoTo exitEnd:
End If
' The sheet name better match or else...
SheetNames = Array("Robert")
Application.ScreenUpdating = False
Set CurWkbk = ActiveWorkbook
Set MstrWkbk = Workbooks.Open(Filename:=MstrWkbkName)
okToContinue = True
For sCtr = LBound(SheetNames) To UBound(SheetNames)
' Current Daily Workbook reference/error check
If WorksheetExists(SheetNames(sCtr), CurWkbk) = False Then
MsgBox CurWkbk.Name & " doesn't have a sheet named: " _
& SheetNames(sCtr)
okToContinue = False
End If
' Master append Workbook reference/error check
If WorksheetExists(SheetNames(sCtr), MstrWkbk) = False Then
MsgBox MstrWkbk.Name & " doesn't have a sheet named: " _
& SheetNames(sCtr)
okToContinue = False
End If
Next sCtr
If okToContinue = False Then
MstrWkbk.Close savechanges:=False
MsgBox "Please fix those worksheet names!"
GoTo exitNow:
End If
For sCtr = LBound(SheetNames) To UBound(SheetNames)
With CurWkbk.Worksheets(SheetNames(sCtr))
Set RngToCopy = .Range("a11:d20")
' & .Cells(.Rows.Count, "D").End(xlUp).Row)
End With
With MstrWkbk.Worksheets(SheetNames(sCtr))
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With
RngToCopy.Copy
DestCell.PasteSpecial Paste:=xlPasteValues
'RngToCopy.Copy _
'Destination:=DestCell
Next sCtr
MstrWkbk.Close savechanges:=True
exitNow:
Application.ScreenUpdating = True
MsgBox "Data was uploaded to the Master Append File, please close the
application. When closing Excel will ask you if you want to save to the
local drive, select NO! Always open the template link from the network
drive, thanks - Ray."
' Insert today's date into cell E1 for duplicate comparison
Range("E1").Value = Date
exitEnd:
End Sub
Function WorksheetExists(SheetName As Variant, _
Optional WhichBook As Workbook) As Boolean
'from Chip Pearson
Dim WB As Workbook
Set WB = IIf(WhichBook Is Nothing, ThisWorkbook, WhichBook)
On Error Resume Next
WorksheetExists = CBool(Len(WB.Worksheets(SheetName).Name) > 0)
End Function