airforceone
Board Regular
- Joined
- Feb 14, 2022
- Messages
- 201
- Office Version
- 2019
- 2016
- Platform
- Windows
coming from this thread String Parsing
I was able to convert @Peter_SSs function code to an ordinary procedure. (thanks again @Peter_SSs )
But got hit by another roadblock. what I'm trying to achieved here is to process all rows and output in their respective cell address.
I think the code
outside of the loop is causing the "Run-time error '5'; Invalid Procedure call or argument" in
I was able to convert @Peter_SSs function code to an ordinary procedure. (thanks again @Peter_SSs )
VBA Code:
Sub PetListII()
Dim RX As Object, M As Object, RXCtr As Integer
Dim K As Integer, ConfisKated As String, FullName As Variant, MaxNumero() As Integer
Set WSCopy = ActiveSheet
ActiveSheet.Select
'Find the last non-blank cell in row 1
LastRow = Cells(rows.Count, 1).End(xlUp).Row
'Find the last non-blank cell in COL 1
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
ReDim MaxNumero(LastRow)
'------------------------------
'
' Count The "," in a string
' Result will be used for the looping sequence
'
'------------------------------
For K = 2 To LastRow
MaxNumero(K) = Len(WSCopy.Range("A" & K)) - Len(Application.WorksheetFunction.Substitute(WSCopy.Range("A" & K), ",", "")) + 1
Next K
LastMaxNum = WorksheetFunction.Max(MaxNumero)
'------------------------------
'
' RegEx Pattern
' by Peter_SSs
' @ https://www.mrexcel.com/
'
'------------------------------
Set RX = CreateObject("VBScript.RegExp")
RX.Global = True
RX.Pattern = "([^,]+\*.+?)(\,?)(?=([^,]+\*)|$)"
Set M = RX.Execute(Cells(2, 1))
RXCtr = 0
For K = 2 To LastRow
For iCTR = 2 To LastMaxNum
Cells(K, iCTR).Value = M(RXCtr).SubMatches(0)
RXCtr = RXCtr + 1
Next
Next
End Sub
But got hit by another roadblock. what I'm trying to achieved here is to process all rows and output in their respective cell address.
I think the code
VBA Code:
Set M = RX.Execute(Cells(2, 1))
Code:
Cells(K, iCTR).Value = M(RXCtr).SubMatches(0)
X TEMPLATE.xlsm | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | Entry | RESULT | ||||
2 | Dog*Brown,White,Black,Dragon*Golden,Green,Red,Black,Eagle*Red,Black,Green | Dog*Brown,White,Black | Dragon*Golden,Green,Red,Black | Eagle*Red,Black,Green | ||
3 | Dog*Brown,White,Black,Eagle*Red,Black,Green | Dog*Brown,White,Black | Eagle*Red,Black,Green | |||
4 | Dragon*Golden,Green,Red,Black | Dragon*Golden,Green,Red,Black | ||||
5 | Dog*Brown,White,Black,Dragon*Golden,Green,Red,Black,Eagle*Red,Black,Green | Dog*Brown,White,Black | Dragon*Golden,Green,Red,Black | Eagle*Red,Black,Green | ||
6 | Dog*Brown,White,Black,Dragon*Golden,Green,Red,Black,Eagle*Red,Black,Green | Dog*Brown,White,Black | Dragon*Golden,Green,Red,Black | Eagle*Red,Black,Green | ||
StringParsing (3) |