可能重複:
Excel clear cells based on contents of a list in another sheetExcel中找到與在另一片代替基於列表的內容的單元格內容
在Excel clear cells based on contents of a list in another sheet bonCodigo幫助我有柱VBA宏腳本行範圍指定爲從Sheet1的A列中獲取單詞,然後在Sheet2列中找到它們作爲精確匹配以清除已找到的單詞。在Sheet3中生成結果。
這是VBA代碼,不會說:
Sub matchAndClear()
Dim ws As Worksheet
Dim arrKeys As Variant, arrData As Variant
Dim i As Integer, j As Integer, k As Integer
'-- here we take keys column from Sheet 1 into a 1D array
arrKeys = WorksheetFunction.Transpose(Sheets(1).Range("A1:A38").Value)
'-- here we take to be cleaned-up-range from Sheet 2 into a 2D array
arrData = WorksheetFunction.Transpose(Sheets(2).Range("A1:I100").Value)
'-- here we iterate through each key in keys array searching it in
'-- to-be-cleaned-up array
For i = LBound(arrKeys) To UBound(arrKeys)
For j = LBound(arrData, 2) To UBound(arrData, 2)
'-- when there's a match we clear up that element
If UCase(Trim(arrData(1, j))) = UCase(Trim(arrKeys(i))) Then
arrData(1, j) = " "
End If
'-- when there's a match we clear up that element
If UCase(Trim(arrData(2, j))) = UCase(Trim(arrKeys(i))) Then
arrData(2, j) = " "
End If
Next j
Next i
'-- replace old data with new data in the sheet 2 :)
Sheets(3).Range("A1").Offset(0, 0).Resize(UBound(arrData, 2), _
UBound(arrData)) = Application.Transpose(arrData)
End Sub
這個時候我需要一個稍微不同的VBA幫助。在Sheet1中,此處顯示另一個單詞列表,因此VBA不應查找並清除與Sheet1 A列中找到的單詞表值匹配的單元格內容,而是將找到的值(需要完全匹配)替換爲Sheet1 B列中的值。
謝謝,這似乎是做什麼需要! – CamSpy
@CamSpy高興地幫助!) –
今天我做了一些更多的VBA腳本測試,看起來它只是對前兩列A和B進行了更改,其他列保持不變。你可以看看並修復它嗎? – CamSpy