Set a VBA reference to Microsoft ActiveX Data Objects 2.8 Library.
Create a table to save the new records into. Replace the names Table1 and Table2 in the code with your table names. I did not have to change anything in the nested loops that parsed the designators and built the array.
Code:
Sub NormalizeBOM()
Dim rsSource As ADODB.Recordset
Dim rsDest As ADODB.Recordset
Dim designators() As String
Set rsSource = New ADODB.Recordset
Set rsDest = New ADODB.Recordset
CurrentDb.Execute "DELETE FROM Table2" 'can remove this line, I include it when testing code
rsSource.Open "SELECT * FROM Table1;", CurrentProject.Connection, adOpenForwardOnly, adLockPessimistic
rsDest.Open "SELECT * FROM Table2;", CurrentProject.Connection, adOpenDynamic, adLockPessimistic
While Not rsSource.EOF
Designator = rsSource!Designator
designators = Split(Designator, ",")
'count commas
commacount = Len(Designator) - Len(Replace(Designator, ",", ""))
For r = 1 To commacount + 1
'check for dash
If InStr(designators(r - 1), "-") Then
num1 = Mid(designators(r - 1), 2, 1)
num2 = Right(designators(r - 1), 1)
letter = Left(designators(r - 1), 1)
For n = num1 To num2
If CInt(n) = CInt(num1) Then
designators(r - 1) = letter & n
Else
ReDim Preserve designators(0 To UBound(designators) + 1) As String
designators(UBound(designators)) = letter & n
End If
Next
End If
Next
For s = LBound(designators) To UBound(designators)
rsDest.AddNew
rsDest!Designator = rsSource!Designator
rsDest!PN = rsSource!PN
rsDest!Description = rsSource!Description
rsDest!quantity = rsSource!quantity
rsDest!Reference = Trim(designators(s))
Next
rsSource.MoveNext
Wend
rsDest.Update
End Sub