VBA error not making sense

mhessnm

Board Regular
Joined
Apr 12, 2019
Messages
57
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a form on a spreadsheet in Excel that someone fills out in cells. I want to make the date and time cells highlight yellow when someone forgets to fill them in and exit the sub with a message to fill in the fields.

I swear this code worked last week when I tested it before uploading so others could use. But today, I'm getting an "application-defined or object defined error."

Here is the beginning of the code. In this I set a variable for the name of the sheet (logName) and another variable for the hidden sheet where the form data is copied (masterName). There are three sheets with date and time fields in the same cells on each sheet, and I make sure the cell is the correct background color before proceeding. However, the red text below is where the code hangs up. I don't see anything wrong with my code, and as I wrote above, it worked last week.

Why is it giving me this error now? What is causing the error, and how can I fix it?


Rich (BB code):
Sub save_and_print()

Application.ScreenUpdating = False

Dim logName As String
Dim masterName As String
logName = ActiveSheet.Name
If logName = "Hospital Outcome Log" Then
    masterName = "Hospital Log Master"
ElseIf logName = "On Call Log" Then
    masterName = "On Call Master"
Else
    masterName = "MHC Master"
End If


'Check to see that the two required fields are entered.

Sheets(logName).Range("B5").Interior.Color = RGB(217, 225, 242)
Sheets(logName).Range("E5").Interior.Color = RGB(217, 225, 242)
 
Last edited by a moderator:
Full access...but I think I know the problem and will test. It's one of those d'oh moments where you are embarrassed to admit it. I need to remove protection from the sheets. I didn't have protection on the sheets I tested. And so it hung up when I asked it to change a cell with protection.

God, how stupid, SMH.
Don't feel bad. Little things like this get me all of the time when I distribute "finalized" Workbooks.
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,224,802
Messages
6,181,054
Members
453,014
Latest member
Chris258

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