Hello,
I've been having an issue in trying to resolve a couple of issues I've with a UserForm I'm trying to create.
Currently I have two ComboBoxes that change their list data depending on what the other ComboBox's value is :
Top is ComboBox1, bottom is ComboBox2.
The only values that are in these ComboBoxes are dates. Currently, the data that it's trying to pull from has every date in a list going from 5-01-2022 to 6-01-2022.
As an example of how this is working:
If ComboBox1 has the date 5-11-2022 entered, then ComboBox2 will only show 5-11-2022 to 6-01-2022 rather than 5-01-2022 to 6-01-2022.
If ComboBox2 has 5-11-2022 entered, ComboBox1 would only should 5-01-2022 to 5-11-2022.
Now, the two issues I'm facing :
1.) When I try to enter any data in the UserForm that isn't a "5" to try and select one of the dates, it crashes because the value of 'x' isn't a date.. When I try to change Dim x to something else like 'Variant', it allows me to add a new value, but then the 'y' value stops working because 'x' isn't a date anymore? I think? My objective to to allow a user to make any typos they may make without having everything break and not knowing what to do. So I'd like to have the UserForm function as if the user only used the drop-down and never actually typed. But when they inevitably do type, it'd be great if this run-time 13 error didn't appear.
2.) When entering the last date in the list, in this case it's 6-01-2022, into ComboBox1 then the UserForm crashes with the run-time 381 error.. same thing if the first date is entered into ComboBox2.
Any help would be appreciated!
Thanks!
I've been having an issue in trying to resolve a couple of issues I've with a UserForm I'm trying to create.
Currently I have two ComboBoxes that change their list data depending on what the other ComboBox's value is :
Top is ComboBox1, bottom is ComboBox2.
VBA Code:
Private Sub UserForm_Initialize()
ComboBox1.List = Application.Transpose(Range(Cells(40, 1), Cells(40, Columns.Count).End(xlToLeft)).Value)
ComboBox2.List = Application.Transpose(Range(Cells(40, 1), Cells(40, Columns.Count).End(xlToLeft)).Value)
End Sub
VBA Code:
Private Sub ComboBox1_Change()
Dim x As Date
Dim y As Range
Dim z As Long
If ComboBox1.Value = vbNullString Then
Exit Sub
End If
x = Chart.ComboBox1.Value
With Sheets("Chart")
Set y = .Range("40:40").Find(x, LookIn:=xlValues)
End With
z = y.Column
ComboBox2.List = Application.Transpose(Range(Cells(40, z), Cells(40, Columns.Count).End(xlToLeft)).Value)
End Sub
VBA Code:
Private Sub ComboBox2_Change()
Dim x As Date
Dim y As Range
Dim z As Long
If ComboBox2.Value = vbNullString Then
Exit Sub
End If
x = Chart.ComboBox2.Value
With Sheets("Chart")
Set y = .Range("40:40").Find(x, LookIn:=xlValues)
End With
z = y.Column
ComboBox1.List = Application.Transpose(Range(Cells(40, 1), Cells(40, z)).Value)
End Sub
The only values that are in these ComboBoxes are dates. Currently, the data that it's trying to pull from has every date in a list going from 5-01-2022 to 6-01-2022.
As an example of how this is working:
If ComboBox1 has the date 5-11-2022 entered, then ComboBox2 will only show 5-11-2022 to 6-01-2022 rather than 5-01-2022 to 6-01-2022.
If ComboBox2 has 5-11-2022 entered, ComboBox1 would only should 5-01-2022 to 5-11-2022.
Now, the two issues I'm facing :
1.) When I try to enter any data in the UserForm that isn't a "5" to try and select one of the dates, it crashes because the value of 'x' isn't a date.. When I try to change Dim x to something else like 'Variant', it allows me to add a new value, but then the 'y' value stops working because 'x' isn't a date anymore? I think? My objective to to allow a user to make any typos they may make without having everything break and not knowing what to do. So I'd like to have the UserForm function as if the user only used the drop-down and never actually typed. But when they inevitably do type, it'd be great if this run-time 13 error didn't appear.
2.) When entering the last date in the list, in this case it's 6-01-2022, into ComboBox1 then the UserForm crashes with the run-time 381 error.. same thing if the first date is entered into ComboBox2.
Any help would be appreciated!
Thanks!