Hi,
I don't really know what I am doing when it comes to VBA. I wrote some VBA script to get a job done for me at work.
I am low man on the totem pole and did this to help speed some note taking for myself on my calls.
I can't send my excel sheet from work to home and vice versa so I don't have a copy of the Excel Sheet but it's easy to explain.
I have 3 sections with 8 identical ActiveX checkboxes in each section:
Section 1: Verified (V)
Section 2: Not Verified (N)
Section 3: Not Asked (NA)
Each sections has the following checkboxes (Names in () are names used in Checkboxes)
SSN, Name, Ph#(Ph), Address, Email, DL/ID #(Address), Last Employer(Emp), and DoB.
I can only have 1 checkbox selected in each section: Name can be checked in V but not N or NA.
My code works flawlessly as far as I can tell but I am asking for help to condense my code. I remember back when I did study Programming(20+ years ago) you should reuse code instead of doing the same thing multiple times.
A lot of my code is nearly identical, but I cannot remember how to condense it so I just have 1 code to do it all.
A brief example first - this is code in one of my checkboxes, the code is the same the only difference is the name
'''This code example, it makes sure that only 1 Address is checked by unselecting the others
If chkAddress_N.Value = True Then
chkAddress_V.Value = False
chkAddress_NA.Value = False
End If
GenerateNotes
The following is all my code. I did change a single if statement at the end of GenerteNotes substituted a "#" for the real digit.
Private Sub ResetForm()
chkSSN_V.Value = False
chkSSN_N.Value = False
chkSSN_NA.Value = True
chkName_V.Value = False
chkName_N.Value = False
chkName_NA.Value = True
chkAddress_V.Value = False
chkAddress_N.Value = False
chkAddress_NA.Value = True
chkPh_V.Value = False
chkPh_N.Value = False
chkPh_NA.Value = True
chkEmail_V.Value = False
chkEmail_N.Value = False
chkEmail_NA.Value = True
chkDoB_V.Value = False
chkDoB_N.Value = False
chkDoB_NA.Value = True
chkDL_V.Value = False
chkDL_N.Value = False
chkDL_NA.Value = True
chkEmp_V.Value = False
chkEmp_N.Value = False
chkEmp_NA.Value = True
Range("F1").Value = ""
Range("A6").Value = ""
End Sub
Private Sub GenerateNotes()
Dim strMsg As String
Dim strTempMsg As String
Dim intLen As Integer
Dim intV As Integer 'Number of items verified
Dim intC As Integer 'Count per section
strMsg = "Claimant Verified:" & Chr(10)
intLen = Len(strMsg)
intV = 0
''''''''''''''''''''''''''''''''''''''''''''''
'''' This Section Checks for Verified Info
''''''''''''''''''''''''''''''''''''''''''''''
If chkSSN_V.Value = True Then
strMsg = strMsg & "SSN, "
intV = intV + 1
End If
If chkName_V.Value = True Then
strMsg = strMsg & "Name, "
intV = intV + 1
End If
If chkAddress_V.Value = True Then
strMsg = strMsg & "Address, "
intV = intV + 1
End If
If chkPh_V.Value = True Then
strMsg = strMsg & "Ph#, "
intV = intV + 1
End If
If chkEmail_V.Value = True Then
strMsg = strMsg & "Email, "
intV = intV + 1
End If
If chkDoB_V.Value = True Then
strMsg = strMsg & "DoB, "
intV = intV + 1
End If
If chkDL_V.Value = True Then
strMsg = strMsg & "DL/ID, "
intV = intV + 1
End If
If chkEmp_V.Value = True Then
strMsg = strMsg & "Last Employer, "
intV = intV + 1
End If
If Len(strMsg) > intLen Then
strMsg = Left(strMsg, Len(strMsg) - 2)
End If
''''''''''''''''''''''''''''''''''''''''''''''
'''' This Section Checks for NOT Verified Info
''''''''''''''''''''''''''''''''''''''''''''''
strTempMsg = strMsg
strMsg = ""
intC = 0
strMsg = strMsg & Chr(10) & Chr(10) & "Claimant Did Not Verify:" & Chr(10)
intLen = Len(strMsg)
If chkSSN_N.Value = True Then
strMsg = strMsg & "SSN, "
intC = intC + 1
End If
If chkName_N.Value = True Then
strMsg = strMsg & "Name, "
intC = intC + 1
End If
If chkAddress_N.Value = True Then
strMsg = strMsg & "Address, "
intC = intC + 1
End If
If chkPh_N.Value = True Then
strMsg = strMsg & "Ph#, "
intC = intC + 1
End If
If chkEmail_N.Value = True Then
strMsg = strMsg & "Email, "
intC = intC + 1
End If
If chkDoB_N.Value = True Then
strMsg = strMsg & "DoB, "
intC = intC + 1
End If
If chkDL_N.Value = True Then
strMsg = strMsg & "DL/ID, "
intC = intC + 1
End If
If chkEmp_N.Value = True Then
strMsg = strMsg & "Last Employer, "
intC = intC + 1
End If
If Len(strMsg) > intLen Then
strMsg = Left(strMsg, Len(strMsg) - 2)
End If
If intC > 0 Then
strMsg = strTempMsg & strMsg
Else
strMsg = strTempMsg
End If
''''''''''''''''''''''''''''''''''''''''''''''
'''' This Section Checks Not Asked
''''''''''''''''''''''''''''''''''''''''''''''
strTempMsg = strMsg
strMsg = ""
intC = 0
strMsg = strMsg & Chr(10) & Chr(10) & "I did not ask to verify:" & Chr(10)
intLen = Len(strMsg)
If chkSSN_NA.Value = True Then
strMsg = strMsg & "SSN, "
intC = intC + 1
End If
If chkName_NA.Value = True Then
strMsg = strMsg & "Name, "
intC = intC + 1
End If
If chkAddress_NA.Value = True Then
strMsg = strMsg & "Address, "
intC = intC + 1
End If
If chkPh_NA.Value = True Then
strMsg = strMsg & "Ph#, "
intC = intC + 1
End If
If chkEmail_NA.Value = True Then
strMsg = strMsg & "Email, "
intC = intC + 1
End If
If chkDoB_NA.Value = True Then
strMsg = strMsg & "DoB, "
intC = intC + 1
End If
If chkDL_NA.Value = True Then
strMsg = strMsg & "DL/ID, "
intC = intC + 1
End If
If chkEmp_NA.Value = True Then
strMsg = strMsg & "Last Employer, "
intC = intC + 1
End If
If Len(strMsg) > intLen Then
strMsg = Left(strMsg, Len(strMsg) - 2)
End If
If intC > 0 Then
strMsg = strTempMsg & strMsg
Else
strMsg = strTempMsg
End If
strMsg = strMsg & Chr(10) & Chr(10) & "Manual Verification: "
If intV >= # Then
strMsg = strMsg & "Success"
Range("A6").Value = "Success"
Else
strMsg = strMsg & "Failed"
Range("A6").Value = "Failed"
End If
Range("F1").Value = strMsg
CopyToTheClipboard
End Sub
Private Sub CopyToTheClipboard()
''''Special Note on This Section: my first test, the clipboard had " at the start and end,
'''''so I wrote code to strip them but every other run never generated it, so the code is commented out
Dim strMsg As String
'Dim intLen As Integer
Dim obj As Object
Set obj = New DataObject
strMsg = Range("F1").Value
'intLen = Len(strMsg)
'strMsg = Left(strMsg, intLen - 1)
'strMsg = Right(strMsg, intLen - 1)
obj.SetText strMsg
obj.PutInClipboard
Set obj = Nothing
End Sub
Private Sub chkAddress_N_Click()
If chkAddress_N.Value = True Then
chkAddress_V.Value = False
chkAddress_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkAddress_NA_Click()
If chkAddress_NA.Value = True Then
chkAddress_V.Value = False
chkAddress_N.Value = False
End If
GenerateNotes
End Sub
Private Sub chkAddress_V_Click()
If chkAddress_V.Value = True Then
chkAddress_N.Value = False
chkAddress_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkDL_N_Click()
If chkDL_N.Value = True Then
chkDL_V.Value = False
chkDL_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkDL_NA_Click()
If chkDL_NA.Value = True Then
chkDL_V.Value = False
chkDL_N.Value = False
End If
GenerateNotes
End Sub
Private Sub chkDL_V_Click()
If chkDL_V.Value = True Then
chkDL_N.Value = False
chkDL_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkDoB_N_Click()
If chkDoB_N.Value = True Then
chkDoB_V.Value = False
chkDoB_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkDoB_NA_Click()
If chkDoB_NA.Value = True Then
chkDoB_V.Value = False
chkDoB_N.Value = False
End If
GenerateNotes
End Sub
Private Sub chkDoB_V_Click()
If chkDoB_V.Value = True Then
chkDoB_N.Value = False
chkDoB_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkEmail_N_Click()
If chkEmail_N.Value = True Then
chkEmail_V.Value = False
chkEmail_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkEmail_NA_Click()
If chkEmail_NA.Value = True Then
chkEmail_V.Value = False
chkEmail_N.Value = False
End If
GenerateNotes
End Sub
Private Sub chkEmail_V_Click()
If chkEmail_V.Value = True Then
chkEmail_N.Value = False
chkEmail_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkEmp_N_Click()
If chkEmp_N.Value = True Then
chkEmp_V.Value = False
chkEmp_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkEmp_NA_Click()
If chkEmp_NA.Value = True Then
chkEmp_V.Value = False
chkEmp_N.Value = False
End If
GenerateNotes
End Sub
Private Sub chkEmp_V_Click()
If chkEmp_V.Value = True Then
chkEmp_N.Value = False
chkEmp_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkName_N_Click()
If chkName_N.Value = True Then
chkName_V.Value = False
chkName_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkName_NA_Click()
If chkName_NA.Value = True Then
chkName_V.Value = False
chkName_N.Value = False
End If
GenerateNotes
End Sub
Private Sub chkName_V_Click()
If chkName_V.Value = True Then
chkName_N.Value = False
chkName_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkPh_N_Click()
If chkPh_N.Value = True Then
chkPh_V.Value = False
chkPh_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkPh_NA_Click()
If chkPh_NA.Value = True Then
chkPh_V.Value = False
chkPh_N.Value = False
End If
GenerateNotes
End Sub
Private Sub chkPh_V_Click()
If chkPh_V.Value = True Then
chkPh_N.Value = False
chkPh_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkSSN_N_Click()
If chkSSN_N.Value = True Then
chkSSN_V.Value = False
chkSSN_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub chkSSN_NA_Click()
If chkSSN_NA.Value = True Then
chkSSN_V.Value = False
chkSSN_N.Value = False
End If
GenerateNotes
End Sub
Private Sub chkSSN_V_Click()
If chkSSN_V.Value = True Then
chkSSN_N.Value = False
chkSSN_NA.Value = False
End If
GenerateNotes
End Sub
Private Sub cmdCopy_Click()
CopyToTheClipboard
End Sub
Private Sub cmdOK_Click()
GenerateNotes
End Sub
Private Sub cmdReset_Click()
ResetForm
End Sub
Can anyone help me in condensing my code?
Bookmarks