Hello,
I'm having an issue with a 'Run time error 5, Invalid procedure call or argument ' pop-up.
My full program runs fine in a separate workbook from a module.
When I move it to a userform, it will work without the below section (no pop-up).
With the below section, it runs through this whole section of code and populates the values, but the 'Run time error 5' pop-up comes after it...and the debugger highlights Part 6 " Strt2 = InStrRev(rll.Value, " ", Strt1, vbTextCompare) "
No matter which parts of the below code I remove, 'Run time error 5' pop-up will display, and the debugger will always highlight a different part of the code.
Any thoughts on why the below is causing issues inside a userform?
The goal of the program is to find a phrase in a cell of text, and then extract 5 words that come directly before it by using spaces as a means of locating each one.
I don't see any Public variable conflicts.
I would appreciate any assistance you can provide.
Thank you.
re = Range("B" & Rows.Count).End(xlUp).Row
Set rng = ActiveSheet.Range("B1:B" & re)
Cnt = 1
For Each rll In rng
' Data example: SAN / SAN 88004 SF 80 EA Item long text
'Strt2 is space to right of target data point
'Strt3 is space to left of target data point
' Part 6 extract Unit of Measure
Strt1 = InStrRev(rll.Value, "Item long text", -1, vbTextCompare)
Strt2 = InStrRev(rll.Value, " ", Strt1, vbTextCompare)
Strt3 = InStrRev(rll.Value, " ", Strt1 - 2, vbTextCompare)
Range(Key4 & Cnt).Value = Trim(Mid(rll.Value, Strt3, Strt2 - Strt3))
' Part 7 extract quantity
Strt2 = Strt3
Strt3 = InStrRev(rll.Value, " ", Strt2 - 2, vbTextCompare)
Range(Key5 & Cnt).Value = Trim(Mid(rll.Value, Strt3, Strt2 - Strt3))
' Part 8 locate junk word (print nothing)
Strt2 = Strt3
Strt3 = InStrRev(rll.Value, " ", Strt2 - 1, vbTextCompare)
' DO NOT print anywhere
' Part 9 extract part number
Strt2 = Strt3
Strt3 = InStrRev(rll.Value, "/", Strt2 - 1, vbTextCompare) + 1
Range(Key8 & Cnt).Value = Trim(Mid(rll.Value, Strt3, Strt2 - Strt3))
' Part 10 extract brand abbreviation
Strt2 = Strt3 - 2
Strt3 = InStrRev(rll.Value, " ", Strt2 - 1, vbTextCompare)
Range(Key7 & Cnt).Value = Trim(Mid(rll.Value, Strt3, Strt2 - Strt3))
Cnt = Cnt + 1
Next rll