VBA 删除今天日期之前的行

标签 vba excel

我在 excel 上有一个 csv 文件,它是列的 ~CU。

并且该行不断更新(截至目前为 2606)。

我试着

  • 删除所有 before today's date 的行记录在 D 列
  • 今天的日期没有打字/文本框/人工输入。

  • enter image description here
    Sub deleterows()
    lastrow = Cells(Rows.Count, 4).End(xlUp).Row
    For i = lastrow To 2 Step -1
        If Cells(i, 4).Value < *numeric value* Then Rows(i).EntireRow.Delete
    Next i
    End Sub
    

    最佳答案

    对于日期(和货币),始终建议使用 Value2而不是 Value .

    MSDN:

    The only difference between this property and the Value property is that the Value2 property doesn’t use the Currency and Date data types. You can return values formatted with these data types as floating-point numbers by using the Double data type.



    所以你需要做的就是改变这部分If Cells(i, 4).Value < *numeric value* Then
    有了这个If Cells(i, 4).Value2 < Date Then
    如果 D 列比今天更旧,它评估为真。

    关于VBA 删除今天日期之前的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41470034/

    相关文章:

    sql - Excel - 如何计数(*)和 groupby 类似于 SQL

    excel - SaveAs 功能适用于 Microsoft PC,但不适用于 MAC

    excel - 没有任何空白行的vba剪切和粘贴功能

    excel - 根据下拉列表更改数据透视表过滤器

    c# - 使用 Excel-DNA,如何区分 Excel 加载项函数调用中未指定的参数和缺失的参数?

    excel - 将 XML 节点提取到相应标题下的表中的循环

    vba - Excel VBA - 在范围内增加列引用

    vba - 如何循环遍历具有拆分单元格的单词表格中的所有单元格

    sql-server-2005 - 是什么导致从 SQL Server Reporting Services 导出 Excel 生成异常大的文件?

    excel - 如果 Excel VBA 代码执行过早结束,会触发什么事件?