用于从关键字列表中突出显示和加粗多列实例(excel 2010)的宏

时间:2016-03-23 15:59:05

标签: excel excel-vba macros vba

我尝试使用在[主题] [1]上发布的类似宏。但是,当我修改为将其用于涵盖A列(A1:A36)中的关键字列表的场景时,必须在列B的每个单元格上应用搜索(B2:B100)并以红色和粗体突出显示在B列中找到的单词。下面是我使用的修改后的宏:

  Dim cl As Range
  Dim startPos As Integer
  Dim totalLen As Integer
  Dim searchText As String
  Dim endPos As Integer
  Dim testPos As Integer

 ' specify text to search.
  searchText = "system integration configuration IT"

 ' loop trough all cells in selection/range
  For Each cl In Selection

  totalLen = Len(searchText)
  startPos = InStr(cl, searchText)
  testPos = 0

  Do While startPos > testPos
  With cl.Characters(startPos, totalLen).Font
   .FontStyle = "Bold"
   .ColorIndex = 3
  End With

   endPos = startPos + totalLen
   testPos = testPos + endPos
   startPos = InStr(testPos, searchText)
   Loop

    Next cl

   End Sub

谢谢

0 个答案:

没有答案