У меня есть программа, которая читает тысячи строк и возвращает нужное мне значение. Проблема в том, что для поиска и вставки значения запросу может потребоваться много времени, например, 1 мин, даже когда я сохраняю код, это занимает много времени ...
Я думаю, что именно в этой строке код медленный:
If Sheets("MT950").Cells(line, 1) Like "-}{5:*" Then
Вот мой код:
Function mysolde62(mycurrency As String, swift As String) As Double
Dim SearchString As String
Dim LastLine As Long, line As Long, k As Long
Dim mybegin As Long, myend As Long, test As Long, count As Long
Dim sign As String
Dim myvalue As Double
LastLine = Sheets("MT950").Range("A1").End(xlDown).Row
count = 0
myend = 1
For line = 1 To LastLine
If Sheets("MT950").Cells(line, 1) Like "-}{5:*" Then
SearchString = Sheets("MT950").Range("A" & line).Value
mypos = InStr(1, SearchString, swift, 1)
If mypos <> 0 Then
count = count + 1
End If
End If
Next line
For k = 1 To count
For line = myend To LastLine
If Sheets("MT950").Cells(line, 1) Like "-}{5:*" Then
SearchString = Sheets("MT950").Range("A" & line).Value
mypos = InStr(1, SearchString, swift, 1)
If mypos <> 0 Then
mybegin = line
For linebis = mybegin To LastLine
If Sheets("MT950").Cells(linebis, 1) Like ":62F:*" Then
SearchString = Sheets("MT950").Range("A" & linebis).Value
mypos = InStr(1, SearchString, mycurrency, 1)
If mypos <> 0 Then
myend = linebis
test = 1
End If
Exit For
End If
Next linebis
If test = 1 Then Exit For
End If
End If
Next line
If test = 1 Then Exit For
Next k
sign = Mid(Sheets("MT950").Cells(myend, 1).Value, 5, 1)
myvalue = Mid(Sheets("MT950").Cells(myend, 1).Value, 15)
If sign = "D" Then
mysolde62 = -myvalue
Else
mysolde62 = myvalue
End If
End Function