I have some code which displays a userform with customer address and personal information when I click on their surname.
The problem is that my 'list' worksheet may need to be filtered and so the row order may not match the 'data' worksheet.
Therefore, I need to edit the code so that it doesn't simply display cells from the matching row, but instead finds the row with a matching customerID reference in both sheets?
Thank you
The problem is that my 'list' worksheet may need to be filtered and so the row order may not match the 'data' worksheet.
Therefore, I need to edit the code so that it doesn't simply display cells from the matching row, but instead finds the row with a matching customerID reference in both sheets?
Thank you
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Target.Column = 2 And Target <> "" Then
UserFormCustomerDetails.Label1 = _
Worksheets("Data").Cells(Target.Row, "AB") & vbCrLf & _
Worksheets("Data").Cells(Target.Row, "AC") & vbCrLf & _
Worksheets("Data").Cells(Target.Row, "AD") & vbCrLf & _
Worksheets("Data").Cells(Target.Row, "AE") & vbCrLf & _
Worksheets("Data").Cells(Target.Row, "AF") & vbCrLf & _
Worksheets("Data").Cells(Target.Row, "AG") & vbCrLf & _
Worksheets("Data").Cells(Target.Row, "AH") & vbCrLf
UserFormCustomerDetails.Label2 = _
Worksheets("Data").Cells(Target.Row, "V") & vbCrLf & _
Worksheets("Data").Cells(Target.Row, "AL") & vbCrLf & _
Worksheets("Data").Cells(Target.Row, "AM") & vbCrLf & _
Worksheets("Data").Cells(Target.Row, "AN") & vbCrLf
UserFormCustomerDetails.Show
Else
UserFormCustomerDetails.Hide
End If
End If
End Sub