ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   mandatory cells only if another cell is filled (https://www.excelbanter.com/excel-programming/364707-mandatory-cells-only-if-another-cell-filled.html)

RA

mandatory cells only if another cell is filled
 
I have checked other postings regarding VBA codes for making cells mandatory
if another cell is filled. I have tried the different statements in various
postings but they did not work for me. I need to have C38 mandatory only if
A38 is filled. I also need this condition up to row 46. If cells in column
A are filled then the corresponding rows in column C have to be filled,
otherwise, the file cannot be saved.

Thanks.

Tom Ogilvy

mandatory cells only if another cell is filled
 
in the thisworkbook module:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
set rng = Worksheets("Sheet1").Range("A38:A46")
for each cell in rng
if not isempty(cell) and isempty(cell.offset(0,2)) then
Application.Goto cell.offset(0,2)
Cancel = True
msgbox "Please fill in cells in column C for " & _
vbNewLine & "corresponding filled in cells in column A in rows "
& vbNewLine & "38 to 46. Save is cancelled!"
end if
Next
End Sub

--
Regards,
Tom Ogilvy


"RA" wrote:

I have checked other postings regarding VBA codes for making cells mandatory
if another cell is filled. I have tried the different statements in various
postings but they did not work for me. I need to have C38 mandatory only if
A38 is filled. I also need this condition up to row 46. If cells in column
A are filled then the corresponding rows in column C have to be filled,
otherwise, the file cannot be saved.

Thanks.



All times are GMT +1. The time now is 03:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com