Saving sheet depending to a condition
Saving sheet depending to a condition
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Saving sheet depending to a condition

  1. #1
    New Member
    Join Date
    Apr 2002
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    I want to save my excel sheet according to a condition like A1 = B3. If the condition is false, sheet could not be saved.

    How can I do this? Is it possible?

  2. #2
    Board Regular
    Join Date
    Feb 2002
    Location
    England
    Posts
    212
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    May not be the best way to do this but this code works

    Sub saveif()

    If Range("A1") = Range("B3") Then

    ActiveWorkbook.Save
    End If
    End Sub

    HTH

    Matt

  3. #3
    New Member
    Join Date
    Apr 2002
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thank you for your concern,Matt.

    If I want my sheet not to be saved from excel's file-->save or ctrl-->s
    unless a condition is true,
    what should I do?


  4. #4
    New Member
    Join Date
    Apr 2002
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    I compile this source. May be it will be useful for others.

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    Dim wSht As Worksheet
    Dim cel_Warning, cel_Cond1, cel_Cond2 As Range
    Dim allwShts As Sheets
    Dim cel As Range
    Dim i As Integer

    Cancel = False
    Set allwShts = Worksheets

    For Each wSht In allwShts
    Set cel_Warning = wSht.Range("IT2")
    Set cel_Cond1 = wSht.Range("IU2")
    Set cel_Cond2 = wSht.Range("IV2")

    For i = 1 To 20
    If Not IsEmpty(cel_Warning(i)) Then
    If Not cel_Cond1(i).Value = cel_Cond2(i).Value Then
    a = MsgBox(wSht.Name + Chr(13) + cel_Warning(i))
    Cancel = True
    End If
    End If
    Next i
    Next wSht
    If Cancel = True Then
    a = MsgBox("File will not be saved!")
    End If
    End Sub

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com