Parsing alphanumeric data into tabular format

manjeet

New Member
Joined
May 25, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
hi experts,
I have the below data where the numbers represent the number of hours and letters represent the code. For ex: H would represent holiday, CS represents Client services etc. and the numbers before them represent the number of hours corresponding to those codes. Anything to the left of the opening bracket sign represents the available hours, where total hours per week is 40. Right of the opening bracket represents utilization. Is there a way to convert this data into a tabular format where each column represents the unique code (CS, H, V etc.) and the corresponding hours in rows:

De Bruyne32(8H)
Gundogan8(8CS16FP8H)
Neymar24(8H8V)
Ronaldo-(40CS)
Messi-(32CS8H)
Benzema-(8H32L)
Mo Salah40
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Welcome to Mr. Excel.

Would you please provide the results you expect for your sample data for a better understanding of what you want?
 
Upvote 0
Welcome to Mr. Excel.

Would you please provide the results you expect for your sample data for a better understanding of what you want?
NAMEAvailableIPHCSFPVL
De Bruyne32080000
Gundogan80881600
Neymar24080080
Ronaldo00040000
Messi00832000
Benzema00800032
Mo Salah40000000
 
Upvote 0
Well, I brute-forced myself through this and came up with:

Code:
Sub splitvalues()
Dim lr As Long, i As Long, Ostr As String, str As String, str2() As String, str3() As String, j As Long
Dim iCode As String
lr = Cells(Rows.Count, "A").End(xlUp).Row
Range("C2:H" & lr) = 0
For i = 2 To lr
 Ostr = Cells(i, "B")
 Ostr = Right(Ostr, Len(Ostr) - InStr(1, Ostr, "("))
 iCode = InStr(1, Ostr, ")")
  If iCode <> 0 Then
 Ostr = Left(Ostr, iCode - 1)
  Else
  End If
 str = Replace(Ostr, "CS", ",")
 str = Replace(str, "H", ",")
 str = Replace(str, "V", ",")
 str = Replace(str, "L", ",")
 str = Replace(str, "FP", ",")
 str = Replace(str, "IP", ",")

For j = 0 To 9
 Ostr = Replace(Ostr, j, " ")
Next j
 Ostr = Replace(Ostr, "  ", " ")
 
str2 = Split(Ostr, " ")
str3 = Split(str, ",")


For j = 1 To UBound(str2)

 Select Case str2(j)
 
 Case "IP"
 Cells(i, "C") = str3(j - 1)
 
 Case "H"
 Cells(i, "D") = str3(j - 1)
 
 Case "CS"
 Cells(i, "E") = str3(j - 1)
 
 Case "FP"
 Cells(i, "F") = str3(j - 1)
 
 Case "V"
 Cells(i, "G") = str3(j - 1)
 
 Case "L"
 Cells(i, "H") = str3(j - 1)
 
 
 End Select
 
Next j

Next i

End Sub


Book1
ABCDEFGH
1IPHCSFPVL
2De Bruyne32(8H)080000
3Gundogan8(8CS16FP8H)0881600
4Neymar24(8H8V)080080
5Ronaldo-(40CS)0040000
6Messi-(32CS8H)0832000
7Benzema-(8H32L)0800032
8Mo Salah40000000
Sheet1
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top