vba - 在列中的每个单元格中运行方程

标签 vba if-statement excel excel-formula calculated-columns

我正在尝试在我的电子表格中运行一个方程式,该方程式将通过“I”列并删除从现在起 90 天内没有到期日期的每一行......换句话说,我正在尝试将我的电子表格格式化为只需给我一份 list ,列出 future 90 天内到期的所有元素。我放星星的那一行是我难以插入方程的地方。我不知道如何插入方程,但如果它自己在单元格中运行,它看起来像这样 =IF(AND(I11-900),1,0)=1。我会将 Q11 更改为什么,以便在运行方程式时它将应用于 I 列中的每个单元格,而不仅仅是 I 11

Sub DeleteNow()


Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long


With Application
    CalcMode = .Calculation
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
End With

With Sheets("Copy")
    .Select
    ViewMode = ActiveWindow.View
    ActiveWindow.View = xlNormalView
    .DisplayPageBreaks = False
    Firstrow = .UsedRange.Cells(1).Row
    Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
    For Lrow = Lastrow To Firstrow Step -1
        With .Cells(Lrow, "I")

            If Not IsError(.Value) Then

                If ******************** Then .EntireRow.Delete

            End If

        End With

    Next Lrow


End With

ActiveWindow.View = ViewMode
With Application
    .ScreenUpdating = True
    .Calculation = CalcMode
End With

End Sub

最佳答案

我现在没有 XL,所以可能会有一些语法错误,但这对你来说应该容易得多,而且很容易理解和更新。注意我刚刚构建了代码的核心,我留下了你所有的Application水平的东西。

With Sheets("Copy")

    '.Select -> no need to select anything, you can work right with the object
    ViewMode = ActiveWindow.View
    ActiveWindow.View = xlNormalView
    .DisplayPageBreaks = False

    Dim myCol as Integer
    myCol = 9

    'the below assumes your data sets starts in column A and you want to filter on column I
    .UsedRange.AutoFilter myCol, xlLast90Days 'this "xlLast90Days" is most likely not right, but if you do it manually while recording a macro, you will get the correct syntax

     Dim rngDelete as Range
     On Error Resume Next 'in case there are no visible cells
     Set rngDelete = Intersect(.UsedRange, .UsedRange.Offset(1), .Columns(myCol)).SpecialCells(xlCellTypeVisible) 'assumes first row of usedrange is header row

     'if there are values over 90 delete them
     If not rngDelete is Nothing Then rngDelete.EntireRow.Delete

End With

关于vba - 在列中的每个单元格中运行方程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13938993/

相关文章:

VBA MS Access 中的 SQL 命令帮助

excel - 如何从 Outlook 联系人中获取列中列出的名称的电子邮件地址?

excel - 嵌套 IF 语句

java - 如何使用java管理Excel文件中的Excel工作表而不使用第三方库

ms-access - "The data has been changed"从主窗体步进到子窗体时出错

vba - 取消通过 VBA 显示的 'Save As' 对话框时出现运行时错误

java - 在以下情况下,if-else 树是最好的方法吗?

python - 在 python 的 re.search 中一起使用 AND & OR 运算符?

vba - 如何超链接本地文件位置VBA

javascript - 在 AngularJS 中以 CSV、Excel、PDF 格式导出数据