Must fill in a cell before being able to save

SZ11OT9

Board Regular
Joined
Sep 10, 2009
Messages
87
I found this topic, but i would like to do it a bit different.
http://www.mrexcel.com/forum/showthread.php?t=75707

I am creating a form for others to fill in. But they don't fill it completely.
So i want to force them to ;)

What they need to do:

If they fill in Cell G31 or H31 they must also fill in cel F31, before it will save the document.

If they try to save the file without F31 filled, it should give a messagebox that
says: Fill in Volume.

I've got a bit, but it won't work...

Code:
Privatesub Workbook_BeforeSave(ByVal SaveAsUi  As Boolean, Cancel As Boolean) 
 
   Dim msg As String 
 
   If Not Worksheets("Sheet1"). Range("G31").Value Like "##" then 
        msg = "Befor saving, fill in Volume." 
        Cancel = True
    End If
 
   If Not Worksheets("Sheet1").Range("H31").Value Like "##" Then 
        msg = msg & vbCrLf & "Before saving, fill in Volume." 
        Cancel = True
    End If
 
   If Cancel Then
        MsgBox msg 
    End If
 
 End Sub
 
Last edited:
That was what i was doing wrong :shame:

It now runs great on this code:

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As Boolean)
   Dim msg As String
    If Worksheets("Sheet1").Range("G31").Value <> "" And _
        Worksheets("Sheet1").Range("F31").Value = "" Then
        msg = "Before saving, fill in Volume."
        Cancel = True
    End If
    If Worksheets("Sheet1").Range("H31").Value <> "" And _
        Worksheets("Sheet1").Range("F31").Value = "" Then
        msg = "Before saving, fill in Volume."
        Cancel = True
    End If
 
   If Cancel Then
        MsgBox msg
    End If
 End Sub

Thank you all for your time and efford!!!
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim uiValue As Variant, VolumnCell As Range
    Set VolumnCell = ThisWorkbook.Sheets("Sheet1").Range("F31")
    If CStr(VolumnCell.Offset(0, 1)) & CStr(VolumnCell.Offset(0, 2)) <> vbNullString Then
        If CStr(VolumnCell) = vbNullString Then
            uiValue = Application.InputBox("The Volumn must be entered before saving." & vbCr & vbCr & "Volumn:", Type:=7)
            If uiValue = False Then uiValue = vbNullString
            VolumnCell.Value = uiValue
        End If
        Cancel = (CStr(VolumnCell) = vbNullString)
    End If
End Sub
 
Upvote 0
Hello Every one,

Need some help on it, I want to input all cell (Row) Before Column H if user fill any cell in column H, Please look below



A
B
C
D
E
F
G
H
1







Yes
2








3








4









<tbody>
</tbody>

If user input in H1 then have to input all cell before cell H1 (A1:G1)
 
Upvote 0

Forum statistics

Threads
1,215,217
Messages
6,123,675
Members
449,116
Latest member
HypnoFant

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