VBA新手,试图纠正日期输出

时间:2016-01-13 21:45:58

标签: excel vba excel-vba

该程序只输出符合“加号”状态的表单列表以及他们合格的日期。

enter image description here

我目前正在尝试确保没有合格的日期在相邻字段中输出“0”而不是表单的名称。当前程序不会这样做,并想知道我需要添加哪些命令。

enter image description here

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

1 个答案:

答案 0 :(得分:2)

作为一个快速而肮脏的,为什么不只是在Else语句中添加If与您完全相同的内容,而是将行.Cells(iRowDestiny, 2).Value = oSht.Name更改为{ {1}}?那不是你想要的吗?

.Cells(iRowDestiny, 2).Value = 0