saving the blank excel template with vba

smarotol

New Member
Joined
Nov 30, 2016
Messages
2
Hi
Please i need assistance.

I have a vba code that forces a couple of fields to be filled in before saving the workbook which works fine. But the problem now is that as soon as i clear the document to send it out to users to start capturing, it does not allow me to save the document.


Regards and Thanks!
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)


Dim rngCell As Range
Dim lngLstRow As Long, lngTCols As Long
Dim lngRowCheck(1 To 9) As String


lngRowCheck(1) = "A"
lngRowCheck(1) = "B"
lngRowCheck(2) = "H"
lngRowCheck(3) = "K"
lngRowCheck(4) = "L"
lngRowCheck(5) = "M"
lngRowCheck(6) = "N"
lngRowCheck(7) = "T"
lngRowCheck(8) = "X"


lngLstRow = ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row


For i = 1 To UBound(lngRowCheck)
    For Each rngCell In Range(lngRowCheck(i) & "10:" & lngRowCheck(i) & lngLstRow)
        If rngCell.Value = "" Then
            MsgBox ("Please enter a mandatory VALUE in cell " & rngCell.Address)
            rngCell.Select
            Cancel = True
        Exit Sub
        End If
    Next
Next i


End Sub
 

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
If you are using a template, why would you need to save it? You should have the original file intact because templates are normally saved as a different file name, leaving the original file as is. You should be able to just close the file after the before save macro runs without saving it and your original file should still be intact. Or am I missing your point?
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,289
Members
449,077
Latest member
Rkmenon

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