我需要一个宏,该宏将仅更改“注释”范围(12列,200k +行)中任何单元格的字体颜色,其中包含“条件”范围(1列,300行)中的任何搜索词,并且按该范围的字体颜色对所有行进行排序。
我创建了一个模板,可以将数据粘贴到该模板中,该模板将应用包含所有术语的条件格式(190个单独的格式规则),但是处理时间非常长,而当我尝试时会花费更长的时间进行排序(一次1行或对所有“注释”使用自定义排序)。
我需要像条件格式一样更改字体,但是我不想应用条件格式,我只想更改那些单元格的字体,因此当我运行自定义排序时,它不会超过30分钟。
答案 0 :(得分:0)
您可以尝试:
Option Explicit
Sub test()
Dim rngTerms As Range, cellsTerms As Range
Dim rngNotes As Range, cellsNotes As Range
'With statement refers to shee 1
With ThisWorkbook.Worksheets("Sheet1")
'Select & name the area which contains "terms" as TermsRange (Pic. 1)
Set rngTerms = .Range("TermsRange")
'Select & name the area which contains "notes" as NotesRange (Pic. 2)
Set rngNotes = .Range("NotesRange")
For Each cellsTerms In rngTerms
For Each cellsNotes In rngNotes
If cellsTerms = cellsNotes Then
cellsTerms.Font.Color = vbRed
cellsNotes.Font.Color = vbRed
End If
Next
Next
End With
End Sub
图片1: