2023年4月8日 星期六

VBA_針對儲純格中( )內字眼標示顏色

 

針對儲純格中( )內字眼標示顏色,如果同一個儲存格純在兩個(),也會都標示顏色。





Sub ChangeColor()

    Dim cell As Range

    Dim i As Integer, j As Integer

    For Each cell In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)

        If cell.Value <> "" Then

            i = InStr(1, cell.Value, "(")

            j = InStr(1, cell.Value, ")")

            If i > 0 And j > 0 And i < j Then

                cell.Characters(i, j - i + 1).Font.ColorIndex = 5 '修改括號內字元的顏色

                If InStr(j + 1, cell.Value, "(") > 0 Then '判斷是否存在第2個以上的括號

                    k = InStr(j + 1, cell.Value, "(")

                    l = InStr(j + 1, cell.Value, ")")

                    If k > 0 And l > 0 And k < l Then

                        cell.Characters(k, l - k + 1).Font.ColorIndex = 5 '修改第2個以上括號內字元的顏色

                    End If

                End If

            End If

        End If

    Next cell

End Sub




沒有留言:

張貼留言

付費版GPT真的贏Gemini嗎?實際測試分享

今天嘗試請GPT以Python處理三個檔案的資料比對與合併,但付費版GPT給出的代碼卻無法順利執行。於是我轉向Gemini,以相同的提問詞詢問,卻意外發現Gemini所提供的代碼相當精確且更具效率。以我自己目前對Python淺顯的理解,也能看出Gemini所提供的程式碼相對高階且...