Saving sheet depending to a condition

oyuce

New Member
Joined
Apr 16, 2002
Messages
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?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,937
Members
448,534
Latest member
benefuexx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top