Hello
I have a workbook with a userform that I have created to input data into multiple single cell named ranges. Part of my code checks if the data input into the userform is the same as the data already in the named ranges. I need the code to check ALL of the named ranges to the client input data but perform 2 different actions depending on which textbox on the userform is changed. I initially had all the conditions under the one If statement but I don't need the header/footer code to run if the "entity type" or "period end" is changed (just the named range to be updated). If all of the data matches then I want it to exit sub. The code I have is as follows:
Hoping I've explained my scenario well enough. If someone can help me get to the bottom of this it will be greatly appreciated because I've done my head in!
I have a workbook with a userform that I have created to input data into multiple single cell named ranges. Part of my code checks if the data input into the userform is the same as the data already in the named ranges. I need the code to check ALL of the named ranges to the client input data but perform 2 different actions depending on which textbox on the userform is changed. I initially had all the conditions under the one If statement but I don't need the header/footer code to run if the "entity type" or "period end" is changed (just the named range to be updated). If all of the data matches then I want it to exit sub. The code I have is as follows:
VBA Code:
Private Sub CheckDetails()
Dim Etype As String
Dim Cname As String
Dim Ccode As String
Dim PrepBy As String
Dim RevBy As String
Dim PeriodEnd As String
Etype = EntityTypeComboBox.Value
Cname = ClientNameTextBox.Value
Ccode = UCase(ClientCodeTextBox.Value)
PrepBy = UCase(PreparedByTextBox.Value)
RevBy = UCase(ReviewedByTextBox.Value)
PeriodEnd = CDate(PeriodEndTextBox.Value & " " & YearTextBox.Value)
If Etype <> Range("Entity_Type").Value Or PeriodEnd <> Range("Period_End").Value Then
'Transfer information into workbook
Range("Entity_Type").Value = Etype
Range("Period_End").Value = Format(PeriodEnd, "dd mmmm yyyy")
ElseIf Cname <> Range("Client_Name").Value Or Ccode <> Range("Client_Code").Value Or _
PrepBy <> Range("Prepared_By").Value Or RevBy <> Range("Reviewed_By").Value Then
'Transfer information into workbook
Range("Client_Name").Value = Cname
Range("Client_Code").Value = Ccode
Range("Prepared_By").Value = PrepBy
Range("Reviewed_By").Value = RevBy
'Update info on each sheets' header and footer
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
ThisWorkbook.UpdateHeaderFooter ws
Next ws
Application.ScreenUpdating = True
Else: Exit Sub
End If
End Sub
Hoping I've explained my scenario well enough. If someone can help me get to the bottom of this it will be greatly appreciated because I've done my head in!