rharri1972
Board Regular
- Joined
- Nov 12, 2021
- Messages
- 132
- Office Version
- 2019
- Platform
- Windows
I am not really sure this title explains very well as to what I need.
I have a user form with a listbox1 that is populated with several different customers. I also have a listbox 2 at the bottom of the form that will display the order history for whichever customer I click on in listbox1. This happens "on click".
For each individual customer I have a worksheet and the worksheet is named after the customers ID number.
As I enter an order for a customer, I click a command button on the order form... the data is identified by the customers ID number and then the data is sent to the corresponding worksheet.
As it is now, it works perfectly but ONLY IF there is data in the worksheet. If I do not have any data (or orders) for the customer, I get an error message.
It is completely fine for when I click on a customer, if there are no orders, for listbox2 to just show blank instead of getting an error message.
If I get an order and it will be the first order for this customer and I am getting this error then I will not be able to click the "INSERT" button to enter this order. The "INSERT" button is on the same user form under listbox2.
Here is the code i have now:
Private Sub ListBox1_Click()
'highlighting customer to see quote/order history in listbox2
Application.EnableEvents = False
Sheets(ListBox1.List(ListBox1.ListIndex)).Activate
Application.EnableEvents = True
'list box2 show values
Dim lr As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row '<----- pulling data from active sheet
With ListBox2
.ColumnCount = 3
.ColumnWidths = "70;80;80" '<----- Change to desired column widths
.List = ActiveSheet.Range("A1").CurrentRegion.Value
End With
End Sub
Any help will be greatly appreciated!!
I have a user form with a listbox1 that is populated with several different customers. I also have a listbox 2 at the bottom of the form that will display the order history for whichever customer I click on in listbox1. This happens "on click".
For each individual customer I have a worksheet and the worksheet is named after the customers ID number.
As I enter an order for a customer, I click a command button on the order form... the data is identified by the customers ID number and then the data is sent to the corresponding worksheet.
As it is now, it works perfectly but ONLY IF there is data in the worksheet. If I do not have any data (or orders) for the customer, I get an error message.
It is completely fine for when I click on a customer, if there are no orders, for listbox2 to just show blank instead of getting an error message.
If I get an order and it will be the first order for this customer and I am getting this error then I will not be able to click the "INSERT" button to enter this order. The "INSERT" button is on the same user form under listbox2.
Here is the code i have now:
Private Sub ListBox1_Click()
'highlighting customer to see quote/order history in listbox2
Application.EnableEvents = False
Sheets(ListBox1.List(ListBox1.ListIndex)).Activate
Application.EnableEvents = True
'list box2 show values
Dim lr As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row '<----- pulling data from active sheet
With ListBox2
.ColumnCount = 3
.ColumnWidths = "70;80;80" '<----- Change to desired column widths
.List = ActiveSheet.Range("A1").CurrentRegion.Value
End With
End Sub
Any help will be greatly appreciated!!