SilverFreak
Programmer
Hi,
I recently wrote this script to check whether users had entered the correct details on an excel spreadsheet. It worked correctly but I had to repeat it 18 times. So I decided to loop it by putting it into a module and calling it. As far as I can see it should work??? Can you please help?
Private Sub cmdTransfer_Click()
Dim initials As String '/// Make a string variable for initials ///
Dim a, b, c, d As String '/// Initializes checkbox variables ///
Dim w, x, y, z, i, j, k As String '/// Initializes cell variables ///
'/////////////////////////////
'/////// First Row ///////
'/////////////////////////////
If Range("K2").Value = "" Then '/// Check if cell is empty ///
a = "CBox1"
b = "CBox2"
c = "CBox3"
d = "CkBox1"
w = "A2"
x = "B2"
y = "C2"
z = "D2"
i = "I2"
j = "J2"
k = "K2"
MainLoop '/// Starts the MainLoop
'/////////////////////////////
'/////// Second Row //////
'/////////////////////////////
ElseIf Range("K3").Value = "" Then '/// Check if cell is empty ///
a = "CBox4"
b = "CBox5"
c = "CBox6"
d = "CkBox2"
w = "A3"
x = "B3"
y = "C3"
z = "D3"
i = "I3"
j = "J3"
k = "K3"
MainLoop '/// Starts the MainLoop
End If
End Sub
Here is the MainLoop()...
Sub MainLoop()
'/// Checks whether any options are selected ///
If a = False And b = False And c = False And d = False Then
MsgBox "You haven't selected an option. Please try again!", vbExclamation, "Sanctuary"
'/// Checks if the first CheckBox is selected and the other CheckBox's aren't selected ///
ElseIf a = True And b = False And c = False And d = False Then
MsgBox "You have selected to transfer from one account to another.", vbInformation, "Sanctuary"
'/// Makes sure that you have all the needed info to make transaction ///
If Range(w).Value <> "" And Range(x).Value <> "" And Range.Value <> "" And Range(z).Value <> "" Then
'/// Asks for your initials
initials = Application.InputBox("Please enter your initials", "Sanctuary")
'/// Checks if initials were entered, if so puts them onto sheet ///
If initials = "" Then
MsgBox "You didn't enter any initials!", vbExclamation, "Sanctuary"
Else
Range(j).Value = initials
Range(k).Value = "yes"
MsgBox "Your transfer has been accepted.", vbInformation, "Sanctuary"
End If
Else
MsgBox "You haven't entered all the necessary information to make this type of transfer.", vbExclamation, "Sanctuary"
End If
'/// Checks if the second CheckBox is selected and the other CheckBox's aren't selected ///
ElseIf a = False And b = True And c = False And d = False Then
MsgBox "You have selected to transfer a court cost.", vbInformation, "Sanctuary"
'/// Makes sure there is enough info, and not too much ///
If Range(w).Value <> "" And Range(x).Value <> "" And Range.Value = "" And Range(z).Value = "" Then
'/// Asks for your initials
initials = Application.InputBox("Please enter your initials", "Sanctuary")
'/// Checks if initials were entered, if so puts them onto sheet ///
If initials = "" Then
MsgBox "You didn't enter any initials!", vbExclamation, "Sanctuary"
Else
Range(j).Value = initials
Range(k).Value = "yes"
MsgBox "Your transfer has been accepted.", vbInformation, "Sanctuary"
End If
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value <> "" And Range(z).Value = "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value = "" And Range(z).Value <> "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value <> "" And Range(z).Value <> "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// If it gets this far, you haven't entered enough info ///
Else
MsgBox "You haven't entered all the necessary information to make this type of transfer.", vbExclamation, "Sanctuary"
End If
'/// Checks if the third CheckBox is selected and the other CheckBox's aren't selected ///
ElseIf a = False And b = False And c = True And d = False Then
MsgBox "You have selected to transfer a Sundry Debt.", vbInformation, "Sanctuary"
If Range(w).Value <> "" And Range(x).Value <> "" And Range.Value = "" And Range(z).Value = "" Then
'/// Asks for your initials
initials = Application.InputBox("Please enter your initials", "Sanctuary")
'/// Checks if initials were entered, if so puts them onto sheet ///
If initials = "" Then
MsgBox "You didn't enter any initials!", vbExclamation, "Sanctuary"
Else
Range(j).Value = initials
Range(k).Value = "yes"
MsgBox "Your transfer has been accepted.", vbInformation, "Sanctuary"
End If
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value <> "" And Range(z).Value = "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value = "" And Range(z).Value <> "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value <> "" And Range(z).Value <> "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// If it gets this far, you haven't entered enough info ///
Else
MsgBox "You haven't entered all the necessary information to make this type of transfer.", vbExclamation, "Sanctuary"
End If
'/// Checks if the fourth CheckBox is selected and the other CheckBox's aren't selected ///
ElseIf a = False And b = False And c = False And d = True Then
MsgBox "You have selected to transfer an amount. Please make sure that you enter what sort of transaction this is.", vbInformation, "Sanctuary"
If Range(i).Value <> "" Then
'/// Asks for your initials
initials = Application.InputBox("Please enter your initials", "Sanctuary")
'/// Checks if initials were entered, if so puts them onto sheet ///
If initials = "" Then
MsgBox "You didn't enter any initials!", vbExclamation, "Sanctuary"
Else
Range(j).Value = initials
Range(k).Value = "yes"
MsgBox "Your transfer has been accepted.", vbInformation, "Sanctuary"
End If
Else
MsgBox "You didn't enter what type transfer this was meant to be. Please try again.", vbExclamation, "Sanctuary"
End If
Else
MsgBox "You have selected more than one option. Please try again.", vbInformation, "Sanctuary"
End If
End Sub
Any help would be greatly appreciated.
Thanks, SilverFreak
I recently wrote this script to check whether users had entered the correct details on an excel spreadsheet. It worked correctly but I had to repeat it 18 times. So I decided to loop it by putting it into a module and calling it. As far as I can see it should work??? Can you please help?
Private Sub cmdTransfer_Click()
Dim initials As String '/// Make a string variable for initials ///
Dim a, b, c, d As String '/// Initializes checkbox variables ///
Dim w, x, y, z, i, j, k As String '/// Initializes cell variables ///
'/////////////////////////////
'/////// First Row ///////
'/////////////////////////////
If Range("K2").Value = "" Then '/// Check if cell is empty ///
a = "CBox1"
b = "CBox2"
c = "CBox3"
d = "CkBox1"
w = "A2"
x = "B2"
y = "C2"
z = "D2"
i = "I2"
j = "J2"
k = "K2"
MainLoop '/// Starts the MainLoop
'/////////////////////////////
'/////// Second Row //////
'/////////////////////////////
ElseIf Range("K3").Value = "" Then '/// Check if cell is empty ///
a = "CBox4"
b = "CBox5"
c = "CBox6"
d = "CkBox2"
w = "A3"
x = "B3"
y = "C3"
z = "D3"
i = "I3"
j = "J3"
k = "K3"
MainLoop '/// Starts the MainLoop
End If
End Sub
Here is the MainLoop()...
Sub MainLoop()
'/// Checks whether any options are selected ///
If a = False And b = False And c = False And d = False Then
MsgBox "You haven't selected an option. Please try again!", vbExclamation, "Sanctuary"
'/// Checks if the first CheckBox is selected and the other CheckBox's aren't selected ///
ElseIf a = True And b = False And c = False And d = False Then
MsgBox "You have selected to transfer from one account to another.", vbInformation, "Sanctuary"
'/// Makes sure that you have all the needed info to make transaction ///
If Range(w).Value <> "" And Range(x).Value <> "" And Range.Value <> "" And Range(z).Value <> "" Then
'/// Asks for your initials
initials = Application.InputBox("Please enter your initials", "Sanctuary")
'/// Checks if initials were entered, if so puts them onto sheet ///
If initials = "" Then
MsgBox "You didn't enter any initials!", vbExclamation, "Sanctuary"
Else
Range(j).Value = initials
Range(k).Value = "yes"
MsgBox "Your transfer has been accepted.", vbInformation, "Sanctuary"
End If
Else
MsgBox "You haven't entered all the necessary information to make this type of transfer.", vbExclamation, "Sanctuary"
End If
'/// Checks if the second CheckBox is selected and the other CheckBox's aren't selected ///
ElseIf a = False And b = True And c = False And d = False Then
MsgBox "You have selected to transfer a court cost.", vbInformation, "Sanctuary"
'/// Makes sure there is enough info, and not too much ///
If Range(w).Value <> "" And Range(x).Value <> "" And Range.Value = "" And Range(z).Value = "" Then
'/// Asks for your initials
initials = Application.InputBox("Please enter your initials", "Sanctuary")
'/// Checks if initials were entered, if so puts them onto sheet ///
If initials = "" Then
MsgBox "You didn't enter any initials!", vbExclamation, "Sanctuary"
Else
Range(j).Value = initials
Range(k).Value = "yes"
MsgBox "Your transfer has been accepted.", vbInformation, "Sanctuary"
End If
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value <> "" And Range(z).Value = "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value = "" And Range(z).Value <> "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value <> "" And Range(z).Value <> "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// If it gets this far, you haven't entered enough info ///
Else
MsgBox "You haven't entered all the necessary information to make this type of transfer.", vbExclamation, "Sanctuary"
End If
'/// Checks if the third CheckBox is selected and the other CheckBox's aren't selected ///
ElseIf a = False And b = False And c = True And d = False Then
MsgBox "You have selected to transfer a Sundry Debt.", vbInformation, "Sanctuary"
If Range(w).Value <> "" And Range(x).Value <> "" And Range.Value = "" And Range(z).Value = "" Then
'/// Asks for your initials
initials = Application.InputBox("Please enter your initials", "Sanctuary")
'/// Checks if initials were entered, if so puts them onto sheet ///
If initials = "" Then
MsgBox "You didn't enter any initials!", vbExclamation, "Sanctuary"
Else
Range(j).Value = initials
Range(k).Value = "yes"
MsgBox "Your transfer has been accepted.", vbInformation, "Sanctuary"
End If
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value <> "" And Range(z).Value = "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value = "" And Range(z).Value <> "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// Else, check if too much info ///
ElseIf Range(w).Value <> "" And Range(x).Value <> "" And Range.Value <> "" And Range(z).Value <> "" Then
MsgBox "You have entered too much information for this type of transaction!", vbExclamation, "Sanctuary"
'/// If it gets this far, you haven't entered enough info ///
Else
MsgBox "You haven't entered all the necessary information to make this type of transfer.", vbExclamation, "Sanctuary"
End If
'/// Checks if the fourth CheckBox is selected and the other CheckBox's aren't selected ///
ElseIf a = False And b = False And c = False And d = True Then
MsgBox "You have selected to transfer an amount. Please make sure that you enter what sort of transaction this is.", vbInformation, "Sanctuary"
If Range(i).Value <> "" Then
'/// Asks for your initials
initials = Application.InputBox("Please enter your initials", "Sanctuary")
'/// Checks if initials were entered, if so puts them onto sheet ///
If initials = "" Then
MsgBox "You didn't enter any initials!", vbExclamation, "Sanctuary"
Else
Range(j).Value = initials
Range(k).Value = "yes"
MsgBox "Your transfer has been accepted.", vbInformation, "Sanctuary"
End If
Else
MsgBox "You didn't enter what type transfer this was meant to be. Please try again.", vbExclamation, "Sanctuary"
End If
Else
MsgBox "You have selected more than one option. Please try again.", vbInformation, "Sanctuary"
End If
End Sub
Any help would be greatly appreciated.
Thanks, SilverFreak