EXCEL公式運算

2015-03-07 6:35 am
設定公式日子後有括號星期如(三),可在Sheet1的C1輸入:
=TEXT(Sheet2!C1,"d/m/yyyy")&" ("&CHOOSE(WEEKDAY(A8,1),"日","一","二","三","四","五","六")&")"
結果:1/4/2015 (三)

詢問下列事項:
WEEKDAY (要輸入A5,1)結果才是1/4/2015(三)
當輸入WEEKDAY(A6,1)結果才是2/4/2015(四)
=TEXT(Sheet2!C1,"d/m/yyyy")&" ("&CHOOSE(WEEKDAY(A8,1),"日","一","二","三","四","五","六")&")"
上述重複製此公式在Sheet 1 D1至P1儲存格未有自動日期出,要每格人手自行輸入=TEXT(Sheet2!C1,"d/m/yyyy")改為Sheet2!D1,Sheet 2!E1如似類推,才能出答案連同WEEKDAY(A5,1),要每格人手自行輸入,其實WEEKDAY(A5,1)是什麼意思,是不是要人手自行輸入(A5,1)才會轉星期三,人手自行輸入(A6,1)才會轉星期四,有沒有方法電腦自行出結果,不用人手輸入。

當Sheet 1 C2儲存格輸入 =IF(Sheet2!$C2=C$1,"√","")出現 #REF!未有結果,怎解決?是不是因日期加了(三)未能出結果?

若要「星期」可出現「公眾假期」,由於公眾假期日子每年不同,這需要開立一個按年公眾假期清單來參考。如果日期數量不多,直接輸入日期(星期)較簡單,
怎樣可以設定公式日子後有(三)在同一儲存格顯示,如似類推,同時星期六、日及公眾假期的日子在儲存格會出現不同的顏色顯示。
請指教,謝!

回答 (1)

2015-03-08 10:33 pm
✔ 最佳答案
設定公式日子後有括號星期如(三)的公式有誤,WEEKDAY函數的輸入日期須為Sheet2的C1,令同一公式中TEXT和WEEKDAY函數都是參照同一日期,所以應在Sheet1的C1輸入:
=TEXT(Sheet2! C1,"d/m/yyyy")&" ("&CHOOSE(WEEKDAY(Sheet2!C1,1),"日","一","二","三","四","五","六")&")"
WEEKDAY函數是計算出星期幾,星期日是1、星期一是2、…、星期六是7,CHOOSE函數可按WEEKDAY函數傳回值順序配給星期幾。

至於因日期加了(三) 而出#REF!未有結果,可將公式修改如下(把日期轉成文字串比較):
=IF(TEXT(Sheet2!C1,"d/m/yyyy")=LEFT(C$1,LEN(TEXT(工作表2!C1,"d/m/yyyy"))),"√","")

至於星期六、日及公眾假期的日子在儲存格會出現不同的顏色顯示,可用條件格式(conditional formatting)來設定:
1. Select the cells you want to format, in this case cells C1:P1 having dates.
2. Click Conditional formatting > New Rule...
3. In the New Formatting Rule window, select “Use a formula to determine which cells to format”.
4. Enter the formula in the corresponding box.
=IF(ISNUMBER(FIND("六",C1)),1,0)+IF(ISNUMBER(FIND("日",C1)),1,0)+IF(ISNUMBER(FIND("公眾假期",C1)),1,0)
5. Click the Format... button to choose your custom format.
6. Switch between the Font, Border and Fill tabs and play with different options such as font style, pattern color and fill effects to set up the format that works best for you. In this case go to the Fill tab and choose red colour.
7. Make sure the Preview section displays the format you want and if it does, click the OK button to save the rule. If you are not quite happy with the format preview, click the Format... button again and make the edits.
8. Check if the conditional format is effected (星期六、日及公眾假期日子的儲存格出現紅色),if only cell C1 is effected, check the conditional formatting > Manage rules to see if the “applies to” cell range is $C$1$P$1.


收錄日期: 2021-04-11 21:00:51
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20150306000051KK00095

檢視 Wayback Machine 備份