
Sub prova()
'
' prova Macro
Dim stringa, target, target2 As String
Dim npos, output, primapos, lunghezza As Long
stringa = InputBox("inserire stringa")
target = InputBox("inserire target")
target2 = InputBox("inserire target2")
npos = InStr(1, stringa, target)
Do While npos > 0
primapos = npos
If primapos + 4 = InStr(npos + 3, stringa, target2) Then
output = output & primapos & "; "
End If
npos = InStr(npos + 1, stringa, target)
Loop
MsgBox ("è stato trovato in posizione " & output)
'
Application.Goto Reference:="prova"
End Sub
|
Sub prova()
'
' prova Macro
Dim stringa, target, target2 As String
Dim npos, output, primapos, lunghezza As Long
stringa = Application.InputBox("Selezionare ","SELEZIONA RANGE", , , , , , 2)
target = Application.InputBox("Selezionare ", "SELEZIONA RANGE", , , , , , 2)
target2 = Application.InputBox("Selezionare ", "SELEZIONA RANGE", , , , , , 2)
npos = InStr(1, stringa, target)
MsgBox "valore " & target & "trovato in posizione" & npos
Do While npos > 0
primapos = npos
If primapos + 4 = InStr(npos + 3, stringa, target2) Then
output = primapos
End If
npos = InStr(npos + 1, stringa, target)
Loop
MsgBox ("è stato trovato in posizione " & primapos)
'
Application.Goto Reference:="prova"
End Sub
|
Option Explicit Public Function CercaPosSec(stringa As String, Sec1 As String, Sec2 As String) As String Dim Npos As Long Dim Nstr As String Npos = 0 Nstr = "" Do While IsError(Application.Search(Sec1 & "*" & Sec2, stringa, Npos + 1)) = False Npos = Application.Search(Sec1 & "*" & Sec2, stringa, Npos + 1) Nstr = Nstr & Npos & " " Loop CercaPosSec = Nstr End Function |
| scossa's web site |
| Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw) |
Function SequenzaDNA(sDNA As String, sPre As String, sPost As String) As Variant
'by scossa
Dim oRE As Object
Dim oMatchColl As Object
Dim sPatt As String
Dim nPos As Long
Dim j As Long
Dim vRet As Variant
Set oRE = CreateObject("vbscript.regexp")
With oRE
.Global = True
.IgnoreCase = True
sPatt = "(" & sPre & ")(?:[A-Z]{3})(" & sPost & ")"
.Pattern = sPatt
If .test(sDNA) Then
Set oMatchColl = .Execute(sDNA)
With oMatchColl
For j = 0 To .Count - 1
vRet = vRet & oMatchColl(j).firstindex + 1 & " "
Next
End With
Else
vRet = 0
End If
SequenzaDNA = Replace(Trim(vRet), " ", ";")
End With
Set oRE = Nothing
Set oMatchColl = Nothing
End Function
|
