删除列代码中的whats行

时间:2017-11-27 17:20:11

标签: excel vba

我正在尝试从我的数据集中删除项目。 它基本上说“转到B列:V列并查找我的参数,如果这些值在列中,则删除该行。

不幸的是,这段代码不起作用,我不知道为什么。

我尝试将代码分解为1列循环,但是代码正在逐渐完成,我本可以更快地删除数据。

有什么想法?

tmp1(Data1, Data2, Data3, DataItem, Data4) as (
 select Data1, Data2, Data3,
        convert(varchar(max), LEFT(Data4, CHARINDEX('-', Data4 + '-') - 1)),
        convert(varchar(max), STUFF(Data4, 1, CHARINDEX('-', Data4 + '-'), ''))
 from FA_CTE
 union all
 select Data1, Data2, Data3,
        convert(varchar(max), LEFT(Data4, CHARINDEX('-', Data4 + '-') - 1)),
        convert(varchar(max), STUFF(Data4, 1, CHARINDEX('-', Data4 + '-'), ''))
 from tmp1

1 个答案:

答案 0 :(得分:0)

尝试在循环中构建要删除的范围,然后一次性删除所有内容

Sub SellThrough_dataManip()
    Dim rCell As Range, DelRng As Range
    Dim FirstAddress As String

    Application.ScreenUpdating = False

    With ActiveSheet.Columns("B:V")
        Set rCell = .Find(What:="Check" & "CNL" & "TENA" & "cancelled" & "N" & "Z" & "R" & "Y" & "Club" & "#N/A", LookIn:=xlValues, SearchOrder:=xlByColumns)

        If Not rCell Is Nothing Then
            FirstAddress = rCell.Address
            Do
                If DelRng Is Nothing Then
                    Set DelRng = rCell
                Else
                    Set DelRng = Union(DelRng, rCell)
                End If
                Set rCell = .FindNext(rCell)
            Loop While Not rCell.Address = FirstAddress
        End If
    End With
    If Not DelRng Is Nothing Then DelRng.EntireRow.Delete
End Sub