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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Can you post some sample data and what you are expecting the function to do?
 
Upvote 0
[TABLE="width: 500"]
<tbody>[TR]
[TD]---begin---begin"partonetype-by-carsparttwo"---<strike></strike>
[/TD]
[TD]=ftwo(a1)
[/TD]
[TD]---begin---begin"cars"---<strike></strike>
[/TD]
[/TR]
[TR]
[TD]---begin---begin"partonetype-by-bicyclesparttwo"---
[/TD]
[TD]=ftwo(a2)
[/TD]
[TD]---begin---begin"bicycles"---<strike></strike>
[/TD]
[/TR]
[TR]
[TD]---begin---begin"partonetype-by-carsparttwo"------begin---begin"partonetype-by-bicyclesparttwo"---<strike></strike>
[/TD]
[TD]=ftwo(a3)
[/TD]
[TD]---begin---begin"cars"------begin---begin"partonetype-by-bicyclesparttwo"---<strike></strike>
[/TD]
[/TR]
</tbody>[/TABLE]

in b3 should be:

[TABLE="width: 500"]
<tbody>[TR]
[TD]---begin---begin"cars"------begin---begin"bicycles"---
[/TD]
[/TR]
</tbody>[/TABLE]
 
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,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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