Hi
How can i make this code when opening up the workbook the first time not Clear Data unless it has been transferred.At present if i open up the workbook and i have data in range C32:M36 i can Clear this data even though i have not transferred it.It works fine after i re-enter the data as it will not let me delete until i have transferred.I just need to stop the data from being deleted when the workbook is first opened.So if i press the Clear Data commandbutton when i first open the workbook i then want it to say Transfer the Data first instead of deleting the data....this only happens when the workbook is first opened...it works fine after that
Thanks
Code:
Sub ClearData()
Dim Rng As Range
Set Rng = Sheets("WEEKLY_GRAPH").Range("c32:M36")
On Error Resume Next
Set nmFlag = ThisWorkbook.Names("Flag")
On Error GoTo 0
If Application.WorksheetFunction.CountA(Rng) = Rng.Cells.Count Then
If Evaluate("Flag") Then
Sheets("WEEKLY_GRAPH").Range("c32:M36").ClearContents
If nmFlag Is Nothing Then
ThisWorkbook.Names.Add "Flag", "FALSE", 1
Else
nmFlag.RefersTo = "FALSE"
End If
Else
MsgBox "Transfer the Data first", vbInformation
End If
Else
MsgBox "Cannot be deleted as incomplete", vbCritical
End If
End Sub
Bookmarks