VBA编码将字符串用于斜体

时间:2018-03-18 13:36:04

标签: excel vba excel-vba

我正在编写一个excel VBA代码,用斜体字符串的一部分,使用find和find next,Instr和characters对象。它适用于前12行,以及下面的所有行 - 完整字符串是斜体。我检查了我的范围,看起来一切都很好。

知道是什么导致了这个吗?谢谢。

以下是代码:

Option Explicit

Dim MySearch As Variant
Dim SearchLine As Range
Dim SearchResult As Range
Dim FirstAddress As String
Dim i As Long

Sub Copy_Column_U()

Worksheets("Reading List").Activate

Range("Full_Reference_In_Harvard_Format_Formula").Copy
Range("Full_Reference_In_Harvard_Format").PasteSpecial xlPasteValues

Application.CutCopyMode = False

End Sub

Sub Format_Harvard_Reference()

ThisWorkbook.Worksheets("Reading List").Activate

Call Copy_Column_U

Range("S5").Select
MySearch = ActiveCell.Value
Set SearchLine = Range("Full_Reference_In_Harvard_Format")

For Each MySearch In Range("Journal_Title")
    Set SearchResult = SearchLine.Find(What:=MySearch, MatchCase:=False, LookAt:=xlPart)

    If Not SearchResult Is Nothing Then
        FirstAddress = SearchResult.Address
        Do
            i = InStr(1, SearchResult, MySearch, vbTextCompare)
            SearchResult.Characters(i, Len(MySearch)).Font.Italic = True
            Set SearchResult = SearchLine.FindNext(SearchResult)
        Loop While Not SearchResult Is Nothing And SearchResult.Address <> FirstAddress

    End If

    ActiveCell.Offset(1, 0).Select
Next MySearch

End Sub

0 个答案:

没有答案