kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Code:
Sub test ()
Dim lr As Long
Dim MyRng As Range
Dim sh As Worksheet
Set sh = Sheet1
lr = sh.Cells(Rows.Count, 1).End (xlUp).Row
Set MyRng = sh.Range ("T4:T" & lr)
End Sub
I am looking for a way to be able to set MyRng dynamically using other criteria.
I will be looking at column Y and Z.
The data is sorted by col Y then finally by col Z.
ComboBox1 may contain strings like:
Group 1
Group 2
Group 3 and so on.
ComboBox2 contains strings in the form:
Year1/Year2
The criteria are value (string) from ComboBox1 (pointing to col Y) and ComboBox2 (pointing to col Z).
With that being said, the aim is to be able to:
1. set MyRng to start from where the content in ComboBox2 start in the Worksheet (col Z) and end at where the criteria end in same column. That is I want to capture the range that contains the string in Box2 for the column T as shown in the sample code above.
2. Being an upgrade of the request in #1 above, I want to capture (same year as above in Box2) the Group that is found inside ComboBox1. So say I have inside box1 "Group 1" and Box2 "2020/2021", then I want to set the range to start from where the group 1 starts for 2020/2021.
Thanks in advance.