То же самое происходит в многопоточном режиме (C #, .NET 4.0].
См. следующий код:
Цель печати 1,2,3,4,5 в порядке.
for (int counter = 1; counter <= 5; counter++)
{
new Thread (() => Console.Write (counter)).Start();
}
Результат интересный! (Это может быть как 21334 ...)
Единственное решение - использовать локальные переменные.
for (int counter = 1; counter <= 5; counter++)
{
int localVar= counter;
new Thread (() => Console.Write (localVar)).Start();
}
Невозможно определить, что происходит. К сожалению.
Option Explicit
Public startCell As Range
Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
Dim i As Long
For i = LBound(arr) To UBound(arr)
If arr(i, 1) = stringToBeFound Then
IsInArray = True
Exit For
End If
Next
End Function
Sub AmendMaster()
Const cSource As Variant = "Sheet1" ' Source Worksheet Name/Index
Const cSrc1 As Variant = "A" ' Source Column 1 Letter/Number
Const cSrc2 As Variant = "AC" ' Source Column 2 Letter/Number
Const cSrcFirstR As Long = 3 ' Source First Row Number
Const cTarget As Variant = "Main_Data" ' Target Worksheet Name/Index
Const cTgt1 As Variant = "A" ' Target Column 1 Letter/Number
Const cTgt2 As Variant = "AB" ' Target Column 2 Letter/Number
Const cTgtFirstR As Long = 2 ' Target First Row Number
Dim ws As Worksheet ' Source Worksheet
Dim rngU As Range ' Union Range
Dim vntSrc As Variant ' Source Array
Dim vntTgt As Variant ' Target Array
Dim srcLastR As Long ' Source Last Row Number
Dim tgtLastR As Long ' Target Last Row Number
Dim i As Long ' Array Row Counter
Dim j As Long
With ThisWorkbook.Worksheets(cTarget)
tgtLastR = .Cells(.Rows.Count, cTgt1).End(xlUp).Row
vntTgt = .Range(.Cells(cTgtFirstR, cTgt1), .Cells(tgtLastR, cTgt2))
End With
For i = 1 To Workbooks.Count
If Workbooks(i).Name <> ThisWorkbook.Name _
And Windows(Workbooks(i).Name).Visible = True Then
Debug.Print Workbooks(i).Name
With Workbooks(i).Worksheets(cSource)
srcLastR = .Cells(.Rows.Count, cSrc1).End(xlUp).Row
vntSrc = .Range(.Cells(cSrcFirstR, cSrc1), _
.Cells(srcLastR, cSrc2))
End With
Exit For
End If
Next
For i = 1 To UBound(vntSrc)
For j = 1 To UBound(vntTgt)
If vntTgt(i, UBound(vntTgt, 2)) = "PAID" _
And vntSrc(i, 1) = vntTgt(j, 1) Then
With ThisWorkbook.Worksheets(cTarget)
.Rows(j).Hidden = True ' Delete
End With
End If
Next
Next
End Sub