VBA删除行 [英] VBA delete rows

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

问题描述

我正在尝试为Excel编写VBA代码,该代码根据某些单元格的内容(均在同一列中)删除行.我的程序现在看起来像这样:

I am trying to write a VBA code for excel that deletes rows based on the contents of certain cells (all in the same column). My program right now looks like this:

Sub removeCol()
Dim i As Integer
i = 1
Do While i < 10
If (Cells(i, 2).Text = "a") Then
Rows(i).Delete
i = i + 1
Else
i = i + 1
End If
Loop
End Sub

任何提示,我将不胜感激!现在,这件事根本没有任何影响.

I would be very grateful for any tips! Right now this thing is not having any affect at all.

推荐答案

Sub removeCol()
    Dim i As Integer

    For i = 10 To 1 Step -1
        If Cells(i, 2) = "a" Then
            Rows(i).Delete
        End If
    Next
End Sub

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

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