1

例如,我有一列 18000 个域和另一个包含 210.000 个域的列表,可以找到这 18000 个域。我需要像 CTRL + H 一样进行查找和替换,并且在查找字段中我需要添加整个 18000 个域:像 * domain1.com *、* domain2.com *、* domain3.com * 和替换他们用空格。尝试从 excel 中查找和替换,但在“查找”字段中添加超过 1 个值不起作用。我怎样才能为多个值做到这一点?

4

1 回答 1

1

VBA解决方案

您将需要更改两个工作表引用(数据和编辑工作表)数据 = 源,编辑 = 目标。我还将替换字符串设置为一个变量,以便您可以根据需要将其从空字符串更改。

如果您需要任何其他逻辑(即在比较之前修剪字符串或更改字符串大小写比较),则代码应该相当容易调整。

希望这可以帮助。

Sub ReplaceValues()


Dim dataSht As Worksheet
Dim editSht As Worksheet

Dim dataRange As Range

Dim dataColumn As Long
Dim editColumn As Long


Dim dataEndRow As Long
Dim editEndRow As Long

'sheet that holds all the values we want to find
Set dataSht = Sheet2

'sheet we want to edit
Set editSht = Sheet1


Dim replaceValue As String


'replace value is empty string
replaceValue = ""



'set the column of the data sheet to A
dataColumn = 1

'set the colmun of the sheet to edit to A
editColumn = 1


dataEndRow = dataSht.Cells(dataSht.Rows.count, dataColumn).End(xlUp).Row
editEndRow = editSht.Cells(editSht.Rows.count, editColumn).End(xlUp).Row





'this is the range of the data that we're looking for
Set dataRange = dataSht.Range(dataSht.Cells(1, dataColumn), dataSht.Cells(dataEndRow, dataColumn))


Dim count As Long
Dim val As String

    For i = 1 To editEndRow

    val = editSht.Cells(i, editColumn).Value

    count = Application.WorksheetFunction.CountIf(dataRange, val)

        If count > 0 And Trim(val) <> "" Then

        editSht.Cells(i, editColumn).Value = replaceValue

        End If

    Next i


End Sub

您可以在查找/替换中使用通配符。所以在你的情况下,你应该能够使用类似的东西

domain*在田野里,在田野find what里什么都没有Replace

于 2013-11-05T15:57:04.870 回答