Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Move Data Only After All Required Range Cells Have Been Filled

  1. #11
    Member
    Join Date
    Dec 2012
    Posts
    78
    Rep Power
    12
    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

  2. #12
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Add this code in THISWORKBOOK module

    Code:
    Private Sub Workbook_Open()
        ThisWorkbook.Names("Flag").RefersTo = "FALSE"
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #13
    Member
    Join Date
    Dec 2012
    Posts
    78
    Rep Power
    12
    Thanks Admin....works great

Similar Threads

  1. Replies: 4
    Last Post: 07-02-2013, 11:32 AM
  2. Replies: 2
    Last Post: 06-24-2013, 07:40 PM
  3. Replies: 13
    Last Post: 06-10-2013, 09:05 AM
  4. Replies: 22
    Last Post: 03-19-2013, 07:57 AM
  5. Get last Filled Cell address in a Range.
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 3
    Last Post: 03-24-2012, 01:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •