返回列表 上一主題 發帖

[發問] 增加【取代】的語法。

回復 4# Airman

         
           請參考,檢查看看這是不是你要的:
                      For Each Rng In .Range("AZ1:CC1")
                              Rng.Value = Replace(Rng, "大", "小")
                              If Rng.Interior.ColorIndex = 43 Then
                                    Rng.Interior.ColorIndex = 40
                              ElseIf Rng.Interior.ColorIndex = 8 Then
                                    Rng.Interior.ColorIndex = 39
                              ElseIf Rng.Interior.ColorIndex = 37 Then
                                    Rng.Interior.ColorIndex = 45
                              End If
                        Next

上面的就取代下面的囉;
''''                      Range("AZ1:CC1").Replace "大", "小"
''''
''''                      Range("AZ1:CC1").Select
''''                      Application.FindFormat.Interior.ColorIndex = 43
''''                      Application.ReplaceFormat.Interior.ColorIndex = 40
''''                      Selection.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder _
''''                      :=xlByColumns, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
''''
''''                      Application.FindFormat.Interior.ColorIndex = 8
''''                      Application.ReplaceFormat.Interior.ColorIndex = 39
''''                      Selection.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder _
''''                      :=xlByColumns, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True
''''
''''                      Application.FindFormat.Interior.ColorIndex = 37
''''                      Application.ReplaceFormat.Interior.ColorIndex = 45
''''                      Selection.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder _
''''                      :=xlByColumns, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True

TOP

本帖最後由 Scott090 於 2019-5-18 11:51 編輯

回復 4# Airman



         在簡化試試看:
                With ActiveSheet
                        .Name = "前3小"
                        .Tab.Color = RGB(255, 255, 0)
                        
                        For Each Rng In .Range("AZ1:CC1")
                              Rng.Value = Replace(Rng, "大", "小")
                              i = Rng.Interior.ColorIndex
          Rng.Interior.ColorIndex = IIf(i = 43, 40, IIf(i = 8, 39, IIf(i = 37, 45, i)))

                        Next
              End With

TOP

回復 7# 准提部林

    准大:
    用 Switch 是一個很好的寫法,
     謝謝提醒

TOP

回復 10# Airman


    我沒有其他想法,問看看其他高手大大們是否有其他解法。

TOP

        靜思自在 : 知識要用心體會,才能變成自己的智慧。
返回列表 上一主題