I have a data table with a column that are string values, they are tag numbers. The values are alphanumeric e.g. BL6394B. I am trying to retrieve the first and last value of each continuous alphabetical sequence.
Basically create ranges of the values in the column e.g. BL6394B to BL6394D, BL6395L to BL6395L, BL6399V to BL6399Y.
Picture below portrays a sample of the grouping I am trying to accomplish.
The result could be two string values, grouped data tables, a dictionary variable with key and value, anything really that will make the first value of a continuous alphabetical sequence and the last value retrievable for the entire column of tags.
Hello,
Thank you very much for the help. This solution has gotten me almost all the way there but I am running into an issue. This seems to only take the final alpha character into consideration for the continuous sequence e.g. the ‘F’ in Bl6397F. I need it to identify the entire sequence. For example the Tags below:
BL6394B
BL6394C
BL6395K
BL6395L
BL6396E
BL6397F
BL6397G
BL6398D
BL6398E
BL6398F
BL6399X
BL6399Y
BL8177W
I am getting the following results
Start Tags — End Tags
BL6394B — BL6394C
BL6395K — BL6395L
*BL6396E — BL6397G
BL6398D — BL6398F
BL6399X — BL6399Y
BL8177W — BL8177W
The issue is with the *starred group. The tags in the original data are alphabetically ordered however have a different numerical value before the last character i.e. ‘6’ vs ‘7’ this should result in an additional different grouping. The ideal output being below.
Thank you for the directions. I have tried this approach and have some varying results. I can provide more detailed information after some more testing. Thank you for the help so far.
Replace your original check with this single condition inside the loop:
If currPrefix = prevPrefix AndAlso Asc(currSuffix) = Asc(prevSuffix) + 1 Then
’ continue same group
Else
’ close previous group and start a new group
End If