查找并删除“总计”行 [英] Finding and deleting "Total" row

查看:117
本文介绍了查找并删除“总计”行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在excel VBA代码中有一个特殊的情况。我在excel表中总共排了一行。但是,它既没有说"总"字。细胞也没有任何配方。有10个"总数"细胞,每列一个。我需要循环遍历
列并找到总单元格(通过检查每个单元格的值是否与先前单元格的总和匹配,然后删除该行。所有"总计"单元格都在同一行中。有什么帮助吗?

解决方案

如果列B是其中一列,其中的数字从第2行开始:



Sub TestMacro()

   Dim lRow As Long

   

  对于lRow = 3 To Cells(Rows.Count," B")。End(xlUp).Row - 1

     If Application.Sum (范围("B2:B"& lRow))=单元格(lRow + 1,"B")。值然后是
       Cells (lRow + 1," B")。EntireRow.Delete

       Exit Sub

     结束如果

  下一个lRow

结束次级




I have a peculiar situation in excel VBA code. I have a total row in excel sheet. However, it neither says the word "total" nor does the cell has any formula. There are 10 "total" cells, one for each column. I need to loop through the column and find the total cell (by checking if the value for each cell matches the sum of previous cells and then delete that row. All the "total" cells are in the same row. any help please?

解决方案

If column B is one of the columns, with numbers starting in row 2:

Sub TestMacro()
    Dim lRow As Long
    
    For lRow = 3 To Cells(Rows.Count, "B").End(xlUp).Row - 1
        If Application.Sum(Range("B2:B" & lRow)) = Cells(lRow + 1, "B").Value Then
            Cells(lRow + 1, "B").EntireRow.Delete
            Exit Sub
        End If
    Next lRow
End Sub



这篇关于查找并删除“总计”行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆