Repetition of a function (VBA)

Fixed

Board Regular
Joined
Apr 28, 2017
Messages
95
Hello!

I wrote some function and want to repeat it as many times as it corresponds to the condition.

Function that replaces some part of a string to another by condition:

Code:
Function fone(ByVal sss As String) As String
Dim aaa As Long '---
Dim fff As Long '---
Dim bbb As Long '---
Dim ccc As Long '---
Dim rrr As String '---
Dim ttt As String '---
Dim uuu As String '---
Dim vvv As String '---
On Error GoTo Error_handler:
    aaa = InStr(sss, "type-by-")
    ccc = InStr(aaa, sss, Chr(34))
    ttt = Mid(sss, 1, ccc)
    uuu = Mid(ttt, InStrRev(ttt, "begin") + 6, Len(ttt) - (InStrRev(ttt, "begin") + 6))
    rrr = Replace(uuu, "-by-", "")
    rrr = Replace(rrr, "-of-", "")
    fff = ((Len(uuu) - Len(rrr)) / 4)
     
          Select Case fff
           
          Case 0
          fone = sss
                                                    
           Case 1
           On Error GoTo Error_handler:
           vvv = Replace(Replace(uuu, "partonetype-by-", ""), "parttwo", "")
           fone = Replace(sss, Chr(34) & uuu & Chr(34), Chr(34) & vvv & Chr(34))
           
           Case Is > 1
           fone = sss
                                                    
           End Select
Exit Function
Error_handler:
fone = sss
End Function

Function (UDF) that should repeat the first one more than one time if it corresponds to the condition:

Code:
Function ftwo(ByVal sss As String) As String
ftwo = fone(sss)
End Function

But anyway it make one replace only.
Help me please to fix it.
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Can you post some sample data and what you are expecting the function to do?
 
Upvote 0
---begin---begin"partonetype-by-carsparttwo"---<strike></strike>
=ftwo(a1)
---begin---begin"cars"---<strike></strike>
---begin---begin"partonetype-by-bicyclesparttwo"---
=ftwo(a2)
---begin---begin"bicycles"---<strike></strike>
---begin---begin"partonetype-by-carsparttwo"------begin---begin"partonetype-by-bicyclesparttwo"---<strike></strike>
=ftwo(a3)
---begin---begin"cars"------begin---begin"partonetype-by-bicyclesparttwo"---<strike></strike>

<tbody>
</tbody>

in b3 should be:

---begin---begin"cars"------begin---begin"bicycles"---

<tbody>
</tbody>
 
Upvote 0
I think this solves the problem:
Code:
Function ftwo(ByVal sss As String) As String
Dim cycle As Integer
For cycle = 1 To 100
sss = fone(sss)
Next cycle
ftwo= sss
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,840
Members
449,471
Latest member
lachbee

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