VBA在Excel中删除多行 [英] VBA delete multiple row in excel

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

问题描述

我需要有关此代码的帮助,如何使它删除多行数字?我应该使用"And"功能吗?

I need help with this code, how can I make it do delete multiple row of number? Should I use "And" function ?

谢谢

Sub remove_rows()

    Dim rad As Integer
    Dim Sheet1 As Worksheet

    Set Sheet1 = Worksheets("Export Worksheet")

    Application.ScreenUpdating = False

    'Which row do u want to start with?
    rad = 1

    'Loop row that delete all row in Sheet1 that contain number 2265174

    Do Until IsEmpty(Sheet1.Cells(rad, 1)) = True
        If Sheet1.Cells(rad, 1).Value = "2265174" Then
            Rows(rad).Delete
            rad = rad - 1
        End If
        rad = rad + 1

    Loop

    Application.ScreenUpdating = True

End Sub

推荐答案

考虑:

Sub remove_rows()

    Dim rad As Long, rrad As Long
    Dim Sheet1 As Worksheet

    Set Sheet1 = Worksheets("Export Worksheet")

    Application.ScreenUpdating = False

    'Which row do u want to start with?
    rrad = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row

    'Loop row that delete all row in Sheet1 that contain number 2265174

    For rad = rrad To 1 Step -1
        If Sheet1.Cells(rad, 1).Text = "2265174" Then
            Rows(rad).Delete
        End If
    Next rad

    Application.ScreenUpdating = True

End Sub

注意:

  • 使用 Long ,而不是 Integer
  • 运行循环向后
  • 使用 .Text 捕获数字值和文本值
  • use Long rather than Integer
  • run the loop backwards
  • use .Text to catch both numeric and text values

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

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