If been trying a few different ways to extract numbers from a textbox. Firstly I have successfully cerated an array by delimiting the comma from the textbox data, now i want to search through that array for a "-" to Extract the numbers on either side. finally, which I haven't even got to yet, i then want to repopulate the array with all the number in between the two values.
Eg. Textbox entry = 1,2-4,5-9,10
First array successfully results in
1
2-4
5-9
10
I now want to search those values and extract
2
4
5
9
Finally i want to redim (i think) the ary2 to have all whole numbers between the values EG. 2,3,4 and 5,6,7,8,9
Here's my code including some comment codes that I may not need but was keeping as a reference for trial an error
Private Sub CellNumbers_AfterUpdate()
Dim i, i2, counti As Long
Dim number As Variant
Dim ary() As String
Dim ary2() As String
ary = Split(CStr(CellNumbers.Text), ",")
For i = LBound(ary()) To UBound(ary())
If InStr(1, i, "-", vbTextCompare) Then
ary2 = Split(CStr(ary(i)), "-")
'For i2 = LBound(ary2()) To UBound(ary2())
'ary2 = LBound(ary2()) + 1
'counti = i + 1
'Next
End If
Next
For Each number In ary()
Debug.Print number
Next
For Each number In ary2()
Debug.Print number
Next
'newcount = UBound(ary) + 1 + counti
End Sub
Eg. Textbox entry = 1,2-4,5-9,10
First array successfully results in
1
2-4
5-9
10
I now want to search those values and extract
2
4
5
9
Finally i want to redim (i think) the ary2 to have all whole numbers between the values EG. 2,3,4 and 5,6,7,8,9
Here's my code including some comment codes that I may not need but was keeping as a reference for trial an error
Private Sub CellNumbers_AfterUpdate()
Dim i, i2, counti As Long
Dim number As Variant
Dim ary() As String
Dim ary2() As String
ary = Split(CStr(CellNumbers.Text), ",")
For i = LBound(ary()) To UBound(ary())
If InStr(1, i, "-", vbTextCompare) Then
ary2 = Split(CStr(ary(i)), "-")
'For i2 = LBound(ary2()) To UBound(ary2())
'ary2 = LBound(ary2()) + 1
'counti = i + 1
'Next
End If
Next
For Each number In ary()
Debug.Print number
Next
For Each number In ary2()
Debug.Print number
Next
'newcount = UBound(ary) + 1 + counti
End Sub