A large section of the code is just duplicated.
How would I utilise the main section of code from (If Me.cmbMainExpenditureGroups = "Drawings" Then)
for BOTH of the arguments
Essentially the key part is the difference between:-
AND
Full code is this
How would I utilise the main section of code from (If Me.cmbMainExpenditureGroups = "Drawings" Then)
for BOTH of the arguments
Essentially the key part is the difference between:-
VBA Code:
If Me.txtInvNo.Value > "" Then
.Cells(LastRow, "O") = Format(Me.Calendar1.Value, "mmm/dd")
.Cells(LastRow, "P") = Me.txtInvNo.Value
.Cells(LastRow, "Q") = Me.cmbPaymentMethod
.Cells(LastRow, "S") = Me.txtItemValue.Value
.Cells(LastRow, "R") = Me.cmbSubGroupsList
'***** This Adds the "Comment" to the relevant column cell
.Cells(LastRow, "S").NoteText Text:=UserForm5.txtCommentBox.Value
VBA Code:
Else
.Cells(LastRow, "O") = Format(Me.Calendar1.Value, "mmm/dd")
.Cells(LastRow, "P") = Me.cmbOtherInvoice.Value
.Cells(LastRow, "Q") = Me.cmbPaymentMethod
.Cells(LastRow, "S") = Me.txtItemValue.Value
.Cells(LastRow, "R") = Me.cmbSubGroupsList
'***** This Adds the "Comment" to the relevant column cell
.Cells(LastRow, "S").NoteText Text:=UserForm5.txtCommentBox.Value
VBA Code:
If Me.txtInvNo.Value > "" Then
.Cells(LastRow, "O") = Format(Me.Calendar1.Value, "mmm/dd")
.Cells(LastRow, "P") = Me.txtInvNo.Value
.Cells(LastRow, "Q") = Me.cmbPaymentMethod
.Cells(LastRow, "S") = Me.txtItemValue.Value
.Cells(LastRow, "R") = Me.cmbSubGroupsList
'***** This Adds the "Comment" to the relevant column cell
.Cells(LastRow, "S").NoteText Text:=UserForm5.txtCommentBox.Value
'******* There is an 'ELSE' lower down that handles the statement above
'******* if it's not TRUE
If Me.cmbMainExpenditureGroups = "Drawings" Then
.Cells(LastRow, "U") = Me.txtItemValue.Value
.Cells(LastRow, "U").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Purshases of Stock / Materials" Then
.Cells(LastRow, "V") = Me.txtItemValue.Value
.Cells(LastRow, "V").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Tool, Weather / Safety equip" Then
.Cells(LastRow, "W") = Me.txtItemValue.Value
.Cells(LastRow, "W").NoteText Text:=UserForm4.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Repairs & Renewals" Then
.Cells(LastRow, "X") = Me.txtItemValue.Value
.Cells(LastRow, "X").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Motor Expenses" Then
.Cells(LastRow, "Y") = Me.txtItemValue.Value
.Cells(LastRow, "Y").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Hire Charges" Then
.Cells(LastRow, "Z") = Me.txtItemValue.Value
.Cells(LastRow, "Z").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Liability Insurance" Then
.Cells(LastRow, "AA") = Me.txtItemValue.Value
.Cells(LastRow, "AA").NoteText Text:=UserForm4.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "N.I cont / TGWU" Then
.Cells(LastRow, "AB") = Me.txtItemValue.Value
.Cells(LastRow, "AB").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Gen Insur Office Postage / Stationary" Then
.Cells(LastRow, "AC") = Me.txtItemValue.Value
.Cells(LastRow, "AC").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Misc" Then
.Cells(LastRow, "AD") = Me.txtItemValue.Value
.Cells(LastRow, "AD").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Acquisition of Assets" Then
.Cells(LastRow, "AE") = Me.txtItemValue.Value
.Cells(LastRow, "AE").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Let Property" Then
.Cells(LastRow, "AF") = Me.txtItemValue.Value
.Cells(LastRow, "AF").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Bank Charges" Then
.Cells(LastRow, "AG") = Me.txtItemValue.Value
.Cells(LastRow, "AG").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Utilities / House" Then
.Cells(LastRow, "AH") = Me.txtItemValue.Value
.Cells(LastRow, "AH").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Income Tax" Then
.Cells(LastRow, "AI") = Me.txtItemValue.Value
.Cells(LastRow, "AI").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Mower Fuel cost" Then
.Cells(LastRow, "AJ") = Me.txtItemValue.Value
.Cells(LastRow, "AJ").NoteText Text:=UserForm5.txtCommentBox.Value
End If
Else
.Cells(LastRow, "O") = Format(Me.Calendar1.Value, "mmm/dd")
.Cells(LastRow, "P") = Me.cmbOtherInvoice.Value
.Cells(LastRow, "Q") = Me.cmbPaymentMethod
.Cells(LastRow, "S") = Me.txtItemValue.Value
.Cells(LastRow, "R") = Me.cmbSubGroupsList
'***** This Adds the "Comment" to the relevant column cell
.Cells(LastRow, "S").NoteText Text:=UserForm5.txtCommentBox.Value
If Me.cmbMainExpenditureGroups = "Drawings" Then
.Cells(LastRow, "U") = Me.txtItemValue.Value
.Cells(LastRow, "U").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Purshases of Stock / Materials" Then
.Cells(LastRow, "V") = Me.txtItemValue.Value
.Cells(LastRow, "V").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Tool, Weather / Safety equip" Then
.Cells(LastRow, "W") = Me.txtItemValue.Value
.Cells(LastRow, "W").NoteText Text:=UserForm4.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Repairs & Renewals" Then
.Cells(LastRow, "X") = Me.txtItemValue.Value
.Cells(LastRow, "X").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Motor Expenses" Then
.Cells(LastRow, "Y") = Me.txtItemValue.Value
.Cells(LastRow, "Y").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Hire Charges" Then
.Cells(LastRow, "Z") = Me.txtItemValue.Value
.Cells(LastRow, "Z").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Liability Insurance" Then
.Cells(LastRow, "AA") = Me.txtItemValue.Value
.Cells(LastRow, "AA").NoteText Text:=UserForm4.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "N.I cont / TGWU" Then
.Cells(LastRow, "AB") = Me.txtItemValue.Value
.Cells(LastRow, "AB").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Gen Insur Office Postage / Stationary" Then
.Cells(LastRow, "AC") = Me.txtItemValue.Value
.Cells(LastRow, "AC").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Misc" Then
.Cells(LastRow, "AD") = Me.txtItemValue.Value
.Cells(LastRow, "AD").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Acquisition of Assets" Then
.Cells(LastRow, "AE") = Me.txtItemValue.Value
.Cells(LastRow, "AE").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Let Property" Then
.Cells(LastRow, "AF") = Me.txtItemValue.Value
.Cells(LastRow, "AF").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Bank Charges" Then
.Cells(LastRow, "AG") = Me.txtItemValue.Value
.Cells(LastRow, "AG").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Utilities / House" Then
.Cells(LastRow, "AH") = Me.txtItemValue.Value
.Cells(LastRow, "AH").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Income Tax" Then
.Cells(LastRow, "AI") = Me.txtItemValue.Value
.Cells(LastRow, "AI").NoteText Text:=UserForm5.txtCommentBox.Value
End If
If Me.cmbMainExpenditureGroups = "Mower Fuel cost" Then
.Cells(LastRow, "AJ") = Me.txtItemValue.Value
.Cells(LastRow, "AJ").NoteText Text:=UserForm5.txtCommentBox.Value
End If
End If
End With