我需要做一個vba代碼來比較兩列中的文本,並突出顯示第二列中的匹配文本。我開始編寫代碼,下面是我到目前爲止的內容。它在第一行工作正常,如何修改代碼以將其應用於整個表格,而不僅僅是第一行。我是VBA新手,任何幫助都會很棒。Excel VBA代碼來比較兩列中的文本字符串,並突出顯示某些文本字符串不是整個單元格?
Sub Test1()
Dim strString$, x&
Dim rngCell As Range
strString = Range("G2").Value
Application.ScreenUpdating = False
For Each rngCell In Range("S2", Range("S" & Rows.Count).End(xlUp))
With rngCell
.Font.ColorIndex = 1
For x = 1 To Len(.Text) - Len(strString) Step 1
If Mid(.Text, x, Len(strString)) = strString Then .Characters(x, Len(strString)).Font.ColorIndex = 5
Next x
End With
Next rngCell
Application.ScreenUpdating = True
End Sub
_I努力擴大它在表中的所有行,我得到錯誤messages_真的嗎?讓我猜猜他們是什麼......不,實際上,你爲什麼不告訴我們? –
@chrisneilsen _它寫在我的屏幕上,你看不懂嗎?_ –