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




沒有留言:

張貼留言

使用Gemini撰寫投資策略執行碼

 本週我嘗試使用 AI 來測試「蹺蹺板投資策略」。有趣的是,付費版 ChatGPT 在撰寫較複雜的策略程式碼時,表現並不如預期,反而是免費版的 Gemini 表現更為出色。不僅能快速生成可執行的程式,還能在我進行策略修正的過程中,協助將提示詞進一步結構化,讓程式更貼近我原本的投資...