Jmoz092
Board Regular
- Joined
- Sep 8, 2017
- Messages
- 184
- Office Version
- 365
- 2011
- Platform
- Windows
- MacOS
Hi, we're having an issue with a workbook_open sub. We want to prompt the user for multiple inputs via message boxes, if the cell that will contain their input is blank at workbook_Open. So, we want the message boxes to continue until we've asked the user for each cell's data that we need, before the workbook is even displayed to them. As usual, we've tried to butcher codes together to reach our goal, but my lack of VBA command vocabulary is holding us back.
Upon workbook_Open, we're getting a compile error (Next without for). Please instruct us how to fix the issue.
Here's our attempt at the code:
Thank you
Upon workbook_Open, we're getting a compile error (Next without for). Please instruct us how to fix the issue.
Here's our attempt at the code:
Code:
[COLOR=#454545][FONT="]Private Sub workbook_open()[/FONT][/COLOR][COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="] [/FONT][/COLOR]
[COLOR=#454545][FONT="]If ActiveSheet.Name = "Sheet 1" Then[/FONT][/COLOR]
[COLOR=#454545][FONT="]ptname1 = InputBox("What is the patient's first name?", "Renaming Sheets")[/FONT][/COLOR]
[COLOR=#454545][FONT="]ptname2 = InputBox("What is the patient's last name?", "Renaming Sheets")[/FONT][/COLOR]
[COLOR=#454545][FONT="]ActiveSheet.Name = ptname2 & ", " & ptname1[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]Else[/FONT][/COLOR]
[COLOR=#454545][FONT="]sheet1.Range("E4").Select[/FONT][/COLOR]
[COLOR=#454545][FONT="]MsgBox "Please enter all of the required information before clicking the yellow SaveAs button."[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]Next[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]If WorksheetFunction.CountA( _[/FONT][/COLOR]
[COLOR=#454545][FONT="]ActiveSheet.Range("E4")) < 1 Then[/FONT][/COLOR]
[COLOR=#454545][FONT="]Range("E4").Select[/FONT][/COLOR]
[COLOR=#454545][FONT="]apptdt = InputBox("What is the date of the Dr Visit?", "Office Appointment Date")[/FONT][/COLOR]
[COLOR=#454545][FONT="]Range("E4").Value = appdt[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]Else[/FONT][/COLOR]
[COLOR=#454545][FONT="]sheet1.Range("E4").Select[/FONT][/COLOR]
[COLOR=#454545][FONT="]MsgBox "Please enter all of the required information before clicking the yellow SaveAs button."[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]Next[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]If WorksheetFunction.CountA( _[/FONT][/COLOR]
[COLOR=#454545][FONT="]ActiveSheet.Range("H6")) < 1 Then[/FONT][/COLOR]
[COLOR=#454545][FONT="]Range("H6").Select[/FONT][/COLOR]
[COLOR=#454545][FONT="]MRN = InputBox("What is the patient's medical record number?", "Medical Record Number")[/FONT][/COLOR]
[COLOR=#454545][FONT="]Range(“H6”).Value = MRN[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]Else[/FONT][/COLOR]
[COLOR=#454545][FONT="]sheet1.Range("E4").Select[/FONT][/COLOR]
[COLOR=#454545][FONT="]MsgBox "Please enter all of the required information before clicking the yellow SaveAs button."[/FONT][/COLOR]
[COLOR=#454545][FONT="]Next[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]If WorksheetFunction.CountA( _[/FONT][/COLOR]
[COLOR=#454545][FONT="]ActiveSheet.Range("B7")) < 1 Then[/FONT][/COLOR]
[COLOR=#454545][FONT="]Range("B7").Select[/FONT][/COLOR]
[COLOR=#454545][FONT="]DOB = InputBox("What is the patient's date of birth?", "Patient Date Of Birth")[/FONT][/COLOR]
[COLOR=#454545][FONT="]Range("B7").Value = DOB[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]Else[/FONT][/COLOR]
[COLOR=#454545][FONT="]sheet1.Range("E4").Select[/FONT][/COLOR]
[COLOR=#454545][FONT="]MsgBox "Please enter all of the required information before clicking the yellow SaveAs button."[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]Next[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]If WorksheetFunction.CountA( _[/FONT][/COLOR]
[COLOR=#454545][FONT="]ActiveSheet.Range("E7")) < 1 Then[/FONT][/COLOR]
[COLOR=#454545][FONT="]Range("E7").Select[/FONT][/COLOR]
[COLOR=#454545][FONT="]Ins = InputBox("What is the name of the patient's insurance plan?", "Primary Insurance")[/FONT][/COLOR]
[COLOR=#454545][FONT="]Range("E7").Value = Ins[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]Else[/FONT][/COLOR]
[COLOR=#454545][FONT="]sheet1.Range("E4").Select[/FONT][/COLOR]
[COLOR=#454545][FONT="]MsgBox "Please enter all of the required information before clicking the yellow SaveAs button."[/FONT][/COLOR]
[COLOR=#454545][FONT="]
[/FONT][/COLOR]
[COLOR=#454545][FONT="]End If[/FONT][/COLOR]
[COLOR=#454545][FONT="]End Sub[/FONT][/COLOR]
Thank you