excelvbafirsttime
New Member
- Joined
- Jan 22, 2013
- Messages
- 1
Hi,
This is a follow up to a thread I've read here about values being entered into cells before being able to save the excel file.
http://www.mrexcel.com/forum/excel-questions/433912-must-fill-cell-before-being-able-save.html
The solution here is fine for one cell, but what I am trying to achieve is the following:
In the workbook we use, everytime a user starts a new line and enters a reference in column A (e.g. cell A3), I want to make it mandatory for them to then complete the rest of the row before saving (e.g. if there is a value in A3, they must then fill in "B3:D3", "F3").
So I want the rest of the workbook to have this rule (e.g. range A1:A1000, if there is a value in an A cell - B,C,D,F on the same row must be complete).
We tried conditional formatting to highlight the cells we want to be mandatory but users are still not filling in all the information so this is our next step.
Heres what I've entered after copying the above threads solution but keep encountering Runtime Error 13 type mismatch. I think I'm missing a parameter, does anyone have any advice? I'm using Excel 2007
Here is the code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim msg As String
If Sheets("CT2013").Range("A1:A100").Value <> "" And _
Sheets("CT2013").Range("B1:D100", "F1:F100").Value = "" Then
msg = "Before saving, please ensure all green cells on your new line are completed."
Cancel = True
End If
If Cancel Then
MsgBox msg
End If
End Sub
This is a follow up to a thread I've read here about values being entered into cells before being able to save the excel file.
http://www.mrexcel.com/forum/excel-questions/433912-must-fill-cell-before-being-able-save.html
The solution here is fine for one cell, but what I am trying to achieve is the following:
In the workbook we use, everytime a user starts a new line and enters a reference in column A (e.g. cell A3), I want to make it mandatory for them to then complete the rest of the row before saving (e.g. if there is a value in A3, they must then fill in "B3:D3", "F3").
So I want the rest of the workbook to have this rule (e.g. range A1:A1000, if there is a value in an A cell - B,C,D,F on the same row must be complete).
We tried conditional formatting to highlight the cells we want to be mandatory but users are still not filling in all the information so this is our next step.
Heres what I've entered after copying the above threads solution but keep encountering Runtime Error 13 type mismatch. I think I'm missing a parameter, does anyone have any advice? I'm using Excel 2007
Here is the code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim msg As String
If Sheets("CT2013").Range("A1:A100").Value <> "" And _
Sheets("CT2013").Range("B1:D100", "F1:F100").Value = "" Then
msg = "Before saving, please ensure all green cells on your new line are completed."
Cancel = True
End If
If Cancel Then
MsgBox msg
End If
End Sub