Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
First off, I'm new to writing macros in excel. I have a created a
simple macro to check if a cell is blank and if it is to change the highlighted color to yellow as a required field indicator. The macro runs fine when I run it manually but I want this to run when the user tries to save the document so it will not let them save their changes until all Required fields are filled in. Here is my code. Can you let me know what I'm doing wrong: Sub Workbook_BeforeSave() Dim rowcount As Integer, msg As String, col As String, cnt As Integer msg = "The highlighted Fields are required." & vbCrLf & _ "Please fill in all required fields." lastrow = (Cells(Rows.Count, "A").End(xlUp).Row) - 1 For i = 2 To lastrow If Cells(i, "A").Value = "" Then Range("A" & i).Interior.ColorIndex = 6 End If Next i For i = 2 To lastrow If Cells(i, "B").Value = "" Then Range("B" & i).Interior.ColorIndex = 6 End If Next i For i = 2 To lastrow If Cells(i, "C").Value = "" Then Range("C" & i).Interior.ColorIndex = 6 End If Next i MsgBox msg, vbOKOnly, "Error: Some Required Fields are missing." End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Disabling BeforeSave event | Excel Programming | |||
BeforeSave Event Question | Excel Programming | |||
BeforeSave event | Excel Discussion (Misc queries) | |||
BeforeSave event | Excel Programming | |||
BeforeSave workbook event | Excel Programming |