【发布时间】:2016-03-26 06:16:26
【问题描述】:
需要 VBA 以返回 ECR > 30 天,其中包含 ECR 所在的“位置”。当您点击简单按钮时。程序需要扫描红色单元格并创建一个数组并将数组放入另一个工作簿。
到目前为止的代码:
Sub easy_button_2()
Dim rw As Long, c As Long, fast As String, X
fast = "Y"
With Workbooks("ECR Log w_fast.xlsm").Sheets("Sheet 3")
With Workbooks("ECR Log w_fast.xlsm").Sheets("Sheet 2")
'clear any previous ECR #s/Location results
rw = Application.Match("ECR #s", .Range(.Cells(3, 1), .Cells(Rows.Count, 1).End(xlUp)), 0)
With .Range(.Cells(rw + 24, 1), .Cells(Rows.Count, 1).End(xlUp))
.Resize(.Rows.Count, 2).Offset(1, 0).ClearContents
End With
'reset the Locations named range
With .Range(.Cells(3, 1), .Cells(3, 1).End(xlDown))
.Resize(.Rows.Count, .Cells(1, Columns.Count).End(xlToLeft).Column).Name = "Locations"
End With
'cycle through the ECRs in Locations' column 1
With .Range("Locations")
For rw = 2 To .Rows.Count
If .Cells(rw, 3) > 30 Or .Cells(rw, 2) = fast Then
For c = 3 To .Columns.Count
If .Cells(rw, c).DisplayFormat.Interior.Color = vbRed Then
.Parent.Cells(Rows.Count, 1).End(xlUp).Resize(1, 2).Offset(1, 0) = _
Array(.Cells(rw, 1).Value2, .Cells(1, c).Value2)
Exit For
End If
Next c
End If
Next rw
End With
End With
End With
'Workbooks.Open Filename:="C:\Users\MJ\Desktop\ECR Monitor.xlsm" 'ThisWorkbook.Activate 结束子
【问题讨论】:
-
在您编辑答案并发布一些代码之前,我认为任何人都无法提供太多帮助
标签: arrays excel vba sorting conditional