返回列表 上一主題 發帖

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

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

測試檔 :[attach]30620[/attach]

備註︰本題提供6個測試檔案。

在目前已經將$B$1︰$AX$1標示開獎號碼的底色之後,在增加下列的需求~
需求︰
1_將第2個工作表(="前3小")的AZ$1︰CC$1的"大"取代為"小"。

2_將第2個工作表(="前3小")的AZ$1︰CC$1的~
"43號底色(圖示)"格式"取代為"40號底色(圖示)";
"8號底色(圖示)"格式"取代為"39號底色(圖示)";
"37號底色(圖示)"格式"取代為"45號底色(圖示)";

以上 懇請各位先進惠予賜教為禱!謝謝!

增加取代的語法.rar (124.67 KB)

回復 1# Airman
不好意思,1#的測試檔放錯了^^"

更新測試檔~ 增加取代的語法(2).rar (123.67 KB)
謹供參考!謝謝!

TOP

本帖最後由 Airman 於 2019-5-17 21:08 編輯

回復 1# Airman

在目前已經將$B$1︰$AX$1標示開獎號碼的底色之後,在增加下列的需求~
補充完整的說明~
在目前已經將(檔案日期下一列開獎號碼之$B$1︰$AX$1標示底色增加"前3小"的工作之後,再增加下列的需求~
謝謝!

TOP

本帖最後由 Airman 於 2019-5-18 04:28 編輯

回復 3# Airman


測試主檔 : (主檔)增加取代的語法.rar (58.53 KB)

在列40~列56插入
                      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

回復 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

回復 6# Scott090


試試這可不可
Rng.Interior.ColorIndex = Switch(i = 43, 40, i = 8, 39, i = 37, 45, i = i, i)))

TOP

回復 7# 准提部林

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

TOP

回復 6# Scott090
Scott090大大 :
OK了!謝謝您的不吝賜正^^

TOP

回復 6# Scott090
Scott090大大 :
再請教一下:
如果不用迴圈  For.....Next
還有其它的語法嗎?
謝謝您^^

TOP

        靜思自在 : 君子為目標,小人為目的。
返回列表 上一主題