![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 3
|
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 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
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 |
|
New Member
Join Date: Apr 2002
Posts: 3
|
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 |
|
New Member
Join Date: Apr 2002
Posts: 3
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|