VBA新手,试图纠正date输出

该程序只输出合格为“加”状态的工作表的列表以及合格的date。

在这里输入图像说明

我目前正试图确保没有限定的date在相邻的字段中输出“0”,而不是纸张的名称。 目前的程序不这样做,并想知道我需要添加什么命令。

在这里输入图像说明

Sub FilterPlusData() Dim oWbk As Workbook Dim oSht As Worksheet Dim oShtDestiny As Worksheet Dim iLoop As Integer Dim iFirstRow As Integer Dim iRows As Integer Dim iRowDestiny As Integer Set oWbk = ThisWorkbook Set oShtDestiny = oWbk.Worksheets("OUTPUT") iFirstRow = 4 For Each oSht In oWbk.Worksheets If oSht.Name <> "OUTPUT" Then If oSht.Range("$A$2").Value = "Date" Then iRows = oSht.Cells(Rows.Count, 1).End(xlUp).Row For iLoop = iFirstRow To iRows If oSht.Cells(iLoop, 19).Value = "PLUS" Then With oShtDestiny iRowDestiny = .Cells(Rows.Count, 1).End(xlUp).Row + 1 .Cells(iRowDestiny, 1).Value = oSht.Cells(iLoop, 1).Value .Cells(iRowDestiny, 2).Value = oSht.Name End With End If Next iLoop End If End If Next oSht 'Order Ascendent iRowDestiny = oShtDestiny.Cells(Rows.Count, 1).End(xlUp).Row + 1 With oShtDestiny.Sort .SetRange Range("$A$3:C" & iRowDestiny) .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub 

作为一个快速和肮脏的,为什么不只是添加一个Else你的If语句,做了完全一样的事情,但你改变了行.Cells(iRowDestiny, 2).Value = oSht.Name .Cells(iRowDestiny, 2).Value = 0 ? 那会不会做你想要的?

 If oSht.Cells(iLoop, 19).Value = "PLUS" Then With oShtDestiny iRowDestiny = .Cells(Rows.Count, 1).End(xlUp).Row + 1 .Cells(iRowDestiny, 1).Value = oSht.Cells(iLoop, 1).Value .Cells(iRowDestiny, 2).Value = oSht.Name End With Else With oShtDestiny iRowDestiny = .Cells(Rows.Count, 1).End(xlUp).Row + 1 .Cells(iRowDestiny, 1).Value = oSht.Cells(iLoop, 1).Value .Cells(iRowDestiny, 2).Value = "0" End With End If