对我的数据进行排序,然后只编辑排序

时间:2016-12-13 18:29:21

标签: excel vba excel-vba

这么长的故事我正在处理一个大型数据集,我想切出切片并在组中编辑它们,所以我的想法是告诉vba对数据进行排序,然后将编辑应用于排序列表。但是,似乎它将这些更改应用于所有内容,包括没有进行排序的标题。

Range("B:B").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$B$2").AutoFilter Field:=2, Criteria1:="=* Manager *", _
        Operator:=xlAnd
rng.Replace " IT ", " IT, "
rng.Replace " Manager ", " Manager, "

enter image description here

正如你在这里看到的那样,在代码仍然使用逗号的那种排序中,没有包含IT标题。有没有可行的方法来确保这些编辑仅应用于当前排序的列表?

编辑:有人要求提供完整的代码,所以这里就是。

Sub Title()

Application.ScreenUpdating = False
Dim rng As Range
Dim ws As Worksheet
Set ws = ActiveSheet
Dim cell As Range
Set rng = ws.Range(ws.Cells(2, 2), ws.Cells(ws.Rows.Count, 2).End(xlUp))

For Each cell In rng
    If InStr(1, cell.Value, " ") > 0 Then
        cell.Value = " " & cell.Value & " "
    End If
Next cell
rng.Replace "  ", " "
'Data Breakdown

'Remove phrases
 rng.Replace "at *", ""
rng.Replace "We're *", ""
rng.Replace "We are *", ""
rng.Replace "we're *", ""
rng.Replace "we are *", ""

Range("B:B").Select
     Selection.AutoFilter
    ActiveSheet.Range("$A$1:$B$2").AutoFilter Field:=2, Criteria1:="=* Manager *", _
        Operator:=xlAnd

rng.Replace " IT ", " IT, "
rng.Replace " Manager ", " Manager, "

0 个答案:

没有答案