遍历表并提取某些值

时间:2018-07-09 19:59:44

标签: excel vba

我有一张表格,其中列出了项目的详细信息及其到期日期。如果项目过期,则将其输出到另一张纸上。

我正在尝试在“过期项目”工作表上创建一个“刷新”按钮,该按钮将遍历该表并提取所有过期项目。

Sub refresh_expired()
    Dim wsMaster As Worksheet: Set wsMaster = Worksheets("MASTER")
    Dim wsList As Worksheet: Set wsList = Worksheets("LIST")

    Dim tblList As ListObject: Set tblList = wsList.ListObjects("digsafe_list")
    Dim tblExp As ListObject: Set tblExp = wsMaster.ListObjects("expired_list")
    Dim tblList_row As ListRow
    Dim tblExp_row As ListRow

    Dim not_empty As String
    Dim temp_digsafe As String, temp_work As String
    Dim temp_date As Date
    Dim tRows As Long, tCols As Long

    If tblList.DataBodyRange.Rows.count <> 0 Then
        Set tblExp_row = tblExp.ListRows.Add
        Set tblList_row = tblList.ListRows.Add

        For i = 1 To tblList.DataBodyRange.Rows.count
            If tblList_row.Range(7, i).Value < 1 Then
                temp_digsafe = tblList_row.Range(1, 1).Value
                tblExp_row.Range(1, i).Value = temp_digsafe

                temp_date = tblList_row.Range(7, i).Value
                tblExp_row.Range(1, 4).Value = temp_date
                i = i + 1
            End If
        Next
   End If
End Sub

0 个答案:

没有答案