Hello,
I am Brazilian, and I'm using an online translator
I'm trying to make a function to break strings of formula for use in a macro that filters values
"!setor1,@E(1,2,3,@Ou(1,4,12,31,@E(a,a,a,a)),@Ou(b,b,b,b))"
@E(1,2,3,@Ou(1,4,12,31,@E(a,a,a,a)),@Ou(b,b,b,b))
>>1,2,3
@Ou(1,4,12,31,@E(a,a,a,a))
>>1,4,12,31
@E(a,a,a,a)
@Ou(b,b,b,b)
I had a function, that of beginning work well
but for a mistake, I modified, and now I am unable to align the idea with the result.
Contfor("!setor1,@E(1,2,3,@Ou(1,4,12,31,@E(a,a,a,a)),@Ou(b,b,b,b))", 3, 0)
=@E(a,a,a,a)
Contfor("!setor1,@E(1,2,3,@Ou(1,4,12,31,@E(a,a,a,a)),@Ou(b,b,b,b))", 3, 1)
=a,a,a,a
I am Brazilian, and I'm using an online translator
I'm trying to make a function to break strings of formula for use in a macro that filters values
"!setor1,@E(1,2,3,@Ou(1,4,12,31,@E(a,a,a,a)),@Ou(b,b,b,b))"
@E(1,2,3,@Ou(1,4,12,31,@E(a,a,a,a)),@Ou(b,b,b,b))
>>1,2,3
@Ou(1,4,12,31,@E(a,a,a,a))
>>1,4,12,31
@E(a,a,a,a)
@Ou(b,b,b,b)
I had a function, that of beginning work well
but for a mistake, I modified, and now I am unable to align the idea with the result.
Contfor("!setor1,@E(1,2,3,@Ou(1,4,12,31,@E(a,a,a,a)),@Ou(b,b,b,b))", 3, 0)
=@E(a,a,a,a)
Contfor("!setor1,@E(1,2,3,@Ou(1,4,12,31,@E(a,a,a,a)),@Ou(b,b,b,b))", 3, 1)
=a,a,a,a
Code:
Public Function Contfor(ByVal TextoX As String, ByVal OcorrenciaX As Long, Optional ByVal ss As Long) As String
Dim pos As Long, Ax As Long, ltx As Long, ax2 As Long
lent1 = Len(TextoX)
For Ax = 1 To lent1
lety = Mid(TextoX, Ax, 1)
If lety = "@" Then pos = pos + 1
If pos = OcorrenciaX Then
nucle = 0: ax2 = Ax
dd = 0
GoTo tex:
End If
Next
Contfor = "erro"
Exit Function
tex:
For Ax = ax2 To lent1
lety = Mid(TextoX, Ax, 1)
If lety = "(" Then
nucle = nucle + 1
If dd = 0 Then nucle0 = Ax
dd = 1
End If
If lety = ")" Then nucle = nucle - 1
If nucle = 0 And dd = 1 Then
If ss = 1 Then
dfg = InStr(nucle0, TextoX, ",@", 1) - 2
dfg1 = InStr(nucle0, TextoX, ")", 1) - 1 ' --<<--
If dfg < 1 Or dfg1 < dfg Then dfg = dfg1 - 1 'Else dfg = dfg - 2
Contfor = Mid(TextoX, nucle0 + 1, dfg - ax2 - 1)
Exit Function
Else
Contfor = Mid(TextoX, ax2, Ax - ax2 + 1)
End If
Exit Function
End If
Next
Contfor = "erro"
End Function