RegEx Row Column Listing Error

airforceone

Board Regular
Joined
Feb 14, 2022
Messages
201
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
coming from this thread String Parsing

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))
outside of the loop is causing the "Run-time error '5'; Invalid Procedure call or argument" in
Code:
Cells(K, iCTR).Value = M(RXCtr).SubMatches(0)

X TEMPLATE.xlsm
ABCD
1EntryRESULT
2Dog*Brown,White,Black,Dragon*Golden,Green,Red,Black,Eagle*Red,Black,GreenDog*Brown,White,BlackDragon*Golden,Green,Red,BlackEagle*Red,Black,Green
3Dog*Brown,White,Black,Eagle*Red,Black,GreenDog*Brown,White,BlackEagle*Red,Black,Green
4Dragon*Golden,Green,Red,BlackDragon*Golden,Green,Red,Black
5Dog*Brown,White,Black,Dragon*Golden,Green,Red,Black,Eagle*Red,Black,GreenDog*Brown,White,BlackDragon*Golden,Green,Red,BlackEagle*Red,Black,Green
6Dog*Brown,White,Black,Dragon*Golden,Green,Red,Black,Eagle*Red,Black,GreenDog*Brown,White,BlackDragon*Golden,Green,Red,BlackEagle*Red,Black,Green
StringParsing (3)
 
until we figure out where is that warning coming from....
Are you able to upload a sample dummy data file where the problem is happening to DropBox/OneDrive/Google Drive etc and provide a shared link here?
 
Upvote 0

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,)
Are you able to upload a sample dummy data file where the problem is happening to DropBox/OneDrive/Google Drive etc and provide a shared link here?

here it is @Peter_SSs

Sample Table

VBA Code:
Sub Pet_Lists()

    Dim RX As Object
    Dim a As Variant
    Dim i As Long
    
'Application.DisplayAlerts = False
    
    Set RX = CreateObject("VBScript.RegExp")
    RX.Global = True
    RX.Pattern = "(\,)(?=([^,]+\*)|$)"
    With Range("A2", Range("A" & rows.Count).End(xlUp))
      a = .Value
      For i = 1 To UBound(a)
        a(i, 1) = RX.Replace(a(i, 1), ";")
      Next i
      With .Offset(, 1)
        .Resize(, 50).ClearContents
        .Value = a
        .TextToColumns DataType:=xlDelimited, Semicolon:=True, Comma:=False, Space:=False, Other:=False
      End With
    End With

'Application.DisplayAlerts = True

End Sub
 
Upvote 0
Thanks for the sample file. I probably have, but don't remember striking this issue before but it appears that the message appears because the destination cells have borders.
For example, just as a test, if you make this change then the code runs without disabling alerts and without the pop-up warning.

Rich (BB code):
.Resize(, 50).ClearContents
.Resize(, 50).Clear

However, I assume that you want the borders, so probably the simplest this is to do what you did - disable alerts & re-enable them at the end. (y)
 
Upvote 0
Thanks for the sample file. I probably have, but don't remember striking this issue before but it appears that the message appears because the destination cells have borders.
For example, just as a test, if you make this change then the code runs without disabling alerts and without the pop-up warning.

Rich (BB code):
.Resize(, 50).ClearContents
.Resize(, 50).Clear

However, I assume that you want the borders, so probably the simplest this is to do what you did - disable alerts & re-enable them at the end. (y)
indeed! the border is causing the problem!
Again @Peter_SSs Thanks mate... I'll just issued the border settings after the code :)
 
Upvote 0

Forum statistics

Threads
1,224,749
Messages
6,180,730
Members
452,995
Latest member
isldboy

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