Я сделаю это как можно более прямым.
Три рабочих листа в игре. Notes, shGather и Delay Report. При обновлении листа Notes он находит задержанные рейсы и автоматически загружает их в лист shGather. Эта функциональность работает просто отлично. Мой вопрос касается события обновления рабочего листа shGather.
У меня есть следующий код на рабочем листе shGather. Намерение состоит в том, чтобы запускать массив каждый раз, когда лист обновляется. Информация о shGather, при необходимости, заполняет отчет о задержке.
Sub wsGather_Change(ByVal Target As Range)
Dim wsg As Worksheet
Dim wsd As Worksheet
Dim a As Long 'Total Array
'Dim b As Long
Dim i As Long 'Rows
Dim j As Long 'Columns
Dim lr As Long 'lr is shorthand for last row in the count
Dim cr As Long 'cr is shorthand for current row
Dim cc As Long 'cc is shorthand for current column
Dim arval As String 'array values
Dim aval As Variant 'A column on the shGather worksheet. This value will determine if the information is added to the array
Dim array1()
If Not Intersect(Target, wsg.Range("A2:A15")) Is Nothing Then
Set wsg = Worksheets("Gather") 'Add data from this worksheet to the array
Set wsd = Worksheets("Delay Report") 'deposit information from the array to this worksheet
lr = wsg.Cells(Rows.Count, "A").End(xlUp).Row
arval = "" 'This will be the total strig value of the individual array values that are captured
a = 0 'counts the total number of rows of data that exist in the array
For i = 2 To lr 'Start the array
aval = wsg.Range("A" & i).Value
If aval = "Y" Then 'Set the search parameters
arval = wsg.Range("B" & i).Value & "~#pop#~" 'Start collecting data with the B column
For j = 7 To 14
arval = arval & wsg.Cells(i, j).Value & "~#pop#~" 'continue collecting information in the various columns
Next j
ReDim Preserve array1(a)
array1(a) = arval
a = a + 1
End If
Next i
wsd.Range("G2:O15").ClearContents 'Clears the inserts range
If a > 0 Then
cr = 2
For i = LBound(array1) To UBound(array1)
cc = 6
newarr = Split(array1(i), "`#pop#~")
For j = LBound(newarr) To UBound(newarr)
wsd.Cells(cr, cc).Value = newarr(j)
cc = cc + 1
Next j
cr = cr + 1
Next i
End If
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Я не могу понять, почему я не получаю результаты вывода массива в Отчет о задержке. Я даже не уверен, что код запускает правильное событие, которое я подозреваю. Лист shGather не имеет прямого ввода от любого пользователя. Он просто собирает данные.
Я подозреваю, что у меня либо неправильное событие, либо что-то не так с моим кодом. Любые идеи будут полезны.
Я потратил много времени, пытаясь понять это, я ближе, но все еще учусь. По крайней мере, на этот раз у меня есть код для отображения.