• 締切済み

年を跨ぐカレンダー【Excel】

tom04の回答

  • tom04
  • ベストアンサー率49% (2537/5117)
回答No.4

こんばんは! 横からお邪魔します。 ↓の画像で左側がSheet1~Sheet12の配置とし、右側が祝日データのSheet13とします。 画像が小さいと思いますので、画面を拡大してSheet13のように表を作成しておいてください。 そして画面左下のSheet見出しの一番左側SheetのSheet見出し上で右クリック → コードの表示 → VBE画面に ↓のコードをコピー&ペーストしておいて、Excel画面に戻ってください。 Private Sub Worksheet_Change(ByVal Target As Range) 'この行から Dim k As Long If Target.Address = "$A$1" Then If IsDate(Target) Then Application.EnableEvents = False With Target .Value = DateSerial(Year(.Value), Month(.Value), 1) .NumberFormatLocal = "yyyy年m月" End With Application.EnableEvents = True For k = 2 To 12 With Worksheets(k).Range("A1") .Value = DateAdd("m", k - 1, Worksheets(1).Range("A1")) .NumberFormatLocal = "yyyy年m月" End With Next k End If End If End Sub 'この行まで これでSheet1のA1セルに日付を入力するとSheet1~Sheet12までA1セルに1か月違いの日付が入ります。 (別Sheetに日付を入れてもなにも変化しません、Sheet見出しの一番左側Sheetのみです) 次にSheet1を選択 → Shiftキーを押しながらSheet12のSheet見出しをクリック! これでSheet1~Sheet12までが作業グループ化されましたので、 ↓の画像のような配置で表を作成します。 日~土まではあらかじめ入力しておきます。 そして画像のA4セル(セルの表示形式はユーザー定義から d としておきます)に =IF(MONTH($A$1-WEEKDAY($A$1)+COLUMN(A1)+7*(ROW(A3)/3-1))=MONTH($A$1),$A$1-WEEKDAY($A$1)+COLUMN(A1)+7*(ROW(A3)/3-1),"") という数式を入れます。 その後A5セルに(Sheet13の祝日名を表示するため) =IF(A4="","",IF(COUNTIF(Sheet13!$B$1:$E$21,A4),INDEX(Sheet13!$A$1:$A$21,SUMPRODUCT((Sheet13!$B$1:$E$21=A4)*ROW(Sheet1!$A$1:$A$21))),"")) という数式を入れ、A4~A6セルを範囲指定 → A6セルのフィルハンドルで土曜のG列までコピー! そのまま(3行が選択されている状態で)下へ3行ずつオートフィルでコピー! 最後にSheet見出し上で右クリック → 作業グループ化解除 これで画像のような感じになります。 ※ 祝日のフォントの色を変えたい場合は条件付き書式で可能ですが、作業グループ化されたままでは できないようですので、1Sheetずつ条件付き書式を設定する必要があるようです。 以上、長々と書きましたが参考になりますかね?m(_ _)m

関連するQ&A

  • カレンダーコントロール

    カレンダーコントロールの初期値を本日の日付に設定したいのですがどこで記入すればいいかわかりません。 calendar1.year、month、dayを利用するのでしょうか

  • java Calendarクラス

    javaで月、日を入力してカレンダーを作成したのですが 年と月のsetでmonth-1はマジックナンバーなので直したいのですが どなたかわかる方教えてください。 package sample; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Test { private final static int firstday = 1; public static void main(String[] args) { //カレンダーのインスタンスを取得します Calendar cal = Calendar.getInstance(); //文字入力 BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); //年を取得 int year =0; //月を取得 int month =0; //最後の日付 int lastDay =0; //月初めの曜日を取得 int week =0; //年妥当性チェック boolean CheckYear = true; //月妥当性チェック boolean CheckMonth = true; try { //年妥当性チェック while(CheckYear){ System.out.println("年を入力してください"); //年を入力します year = Integer.parseInt(input.readLine()); //年が4桁の場合 if(String.valueOf(year).length()==4){ CheckYear = false; }else{ System.out.println("年は4桁で入力してください"); } } //月妥当性チェック while(CheckMonth){ System.out.println("月を入力してください"); //月を入力します month = Integer.parseInt(input.readLine()); //月が1~12の場合 if(month>=1&&month<=12){ CheckMonth = false; }else{ System.out.println("月1~12を入力してください"); } } }catch(IOException e){ System.out.println("数字以外は入力しないでください"); System.out.println("処理を中断します"); return; }catch (Exception a) { System.out.println("数字以外は入力しないでください"); System.out.println("処理を中断します"); return; } //年、月をセットします cal.set(year,month-1,cal.getActualMinimum(Calendar.DATE)); //月初めの曜日を取得 week = cal.get(Calendar.DAY_OF_WEEK); //年月を出力する System.out.println(String.valueOf(year)+"年"+String.valueOf(month)+"月"); //曜日を出力する System.out.println("日 月  火  水  木  金  土"); //最後の日付を取得する lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); /* * 最後の日付を取得する */ if(month==1||month==3||month==7||month==8||month==10||month==12) { lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); }else if(month==4||month==6||month==9||month==11){ lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); }else if(year%4==0&&month==2){ lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); }else if(year%4!=0&&month==2){ lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); } /* * カレンダーを出力する */ //最後の日付まで繰り返す // 最後の日付まで繰り返す for (int i = 1; i <= lastDay; i++) { // 1日とそれ以外で分岐する if (i == 1) { // 1日の曜日位置まで移動する for (int j = 1; j < cal.get(Calendar.DAY_OF_WEEK); j++) { System.out.print(" "); } } else { // 日付を増やす cal.add(Calendar.DAY_OF_MONTH, firstday); } // 1~9と10~で表示を変える if (i < 10) { System.out.print(" " + i); } else { System.out.print(" " + i); } // 土曜日になったら改行する if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) { System.out.println(""); } } } }

  • 万年カレンダーについて

    万年カレンダーについて質問します。例えば、11月10日(月)が休みとした場合に11月10日(月)セルの背景を赤色にする方法を教えて下さい。下記のプログラムに加える記述方法を教えて下さい。 <?php if($_GET['num']==''){ $today_year =date("Y"); $today_month=date("n"); }else{ $timestamp=mktime(0,0,0,date("n")+$_GET['num'],date("d"),date("Y")); $today_year =date("Y",$timestamp); $today_month=date("n",$timestamp); } $current=mktime(0,0,0,$today_month,1,$today_year); $first_day=date("w",$current); $last_day=date("t",$current); ?> <html> <head> <title>万年カレンダ</title> </head> <body> <h1 style="background:#cccccc"> <?php print(date("Y年m月",$current)); ?>のカレンダ</h1> <table border="1" width="300"> <tr> <th>日</th><th>月</th><th>火</th><th>水</th> <th>木</th><th>金</th><th>土</th> </tr> <?php for($i=1;$i<=$first_day+$last_day;$i++){ if($i%7==1){print("<tr>"); } if($i>$first_day){ print("<td>".($i-$first_day)."</td>"); }else{ print("<td>&nbsp;</td>"); } if($i%7==0){print("</tr>");} } ?> </table> </body> </html>

    • ベストアンサー
    • PHP
  • java Calendar作成

    javaでのカレンダー作成についての質問です。 表示イメージ(_はすべて半角スペースの意です) year年month月(今回は2016年04月) _日_月_火_水_木_金_土 _______________1__2_ _3__4__5__6__7__8__9_ 10_11_12_13_14_15_16_ 17_18_19_20_21_22_23_ 24_25_26_27_28_29_30_ public class CalShow { public static void main(String[] args) { java.util.Calendar cal = java.util.Calendar.getInstance(); int year = Integer.parseInt(args[0].substring(0, 4)); int month = Integer.parseInt(args[0].substring(4)); cal.set(java.util.Calendar.YEAR, year); cal.set(java.util.Calendar.MONTH, month - 1); cal.set(java.util.Calendar.DAY_OF_MONTH, 1); //日曜日=1で土曜日=7まで int week = cal.get(java.util.Calendar.DAY_OF_WEEK); //月末日 int lastDay = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH); System.out.println( year + "年" + month + "月"); System.out.println("_日_月_火_水_木_金_土"); //日付のない日数分回す for (int i = 1; i < week ; i ++) { System.out.print("___(半角3マス)"); } String empty; //1日から月末日まで、カレンダーを表示する for (int day = 1 ; day <= lastDay ; day ++) { empty = ""; if (day < 10) { empty = "_"; } System.out.print( empty + day + "_"); ●if ( == java.util.Calendar.SATURDAY) { System.out.println(""); } } } } ●部分で土曜日なら改行、としたいのですが、 上でint weekで土曜日=7と判明しているため、 if ( week == java.util.Calendar.SATURDAY) { とか if ( day % 7 == java.util.Calendar.SATURDAY) { など色々考え付くものを書き込んでいるのですが全く上手く動作しません。 どうしたらよいのかご教授お願いいたします・・・;;

    • ベストアンサー
    • Java
  • カレンダー作成

    C言語初心者です。 西暦と月を入力してその月のカレンダーを作成するプログラムの問題なのですが #include <stdio.h> #define MMAX 12 #define COMP (year - 1) int main(void) {  int i, j, year, month, day, youbi, ycnt, mcnt = 0;  int mday[MMAX] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};  printf("西暦と月を入力して下さい-->");  scanf("%4d%2d, &year, &month");  if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)   mday[1] = 29;  for (i = 0; i < [A]; i++) {   mcnt += mday[i];  }  mcnt++;  [B] = ((COMP + COMP / 4 - COMP / 100 + COMP / 400) + mcnt) % 7;  printf("\n%4d 年%2d 月\n", year, month);  printf("----------------------------\n");  printf(" 日 月 火 水 木 金 土\n");  for (j = 0, ycnt = 0; j < youbi; j++, ycnt++) {   printf(" ");  }  for (day =1; day <= mday[month - 1]; day++) {   if ([C])    printf("[%2d]", day);   else    printf(" %2d ", day);   ycnt++;   if ([D]) {    printf("\n");    ycnt = 0;   }  }  return (0); } [A]、[B]、[C]、[D]に答えを入れなきゃいけないのですが私が考えた答えだと カレンダーの表示すらされません。どこがいけないのでしょうか? #include <stdio.h> #define MMAX 12 #define COMP (year - 1) int main(void) {  int i, j, year, month, day, youbi, ycnt, mcnt = 0;  int mday[MMAX] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};  printf("西暦と月を入力して下さい-->");  scanf("%4d%2d, &year, &month");  if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)   mday[1] = 29;  for (i = 0; i < month; i++) {   mcnt += mday[i];  }  mcnt++;  youbi = ((COMP + COMP / 4 - COMP / 100 + COMP / 400) + mcnt) % 7;  printf("\n%4d 年%2d 月\n", year, month);  printf("----------------------------\n");  printf(" 日 月 火 水 木 金 土\n");  for (j = 0, ycnt = 0; j < youbi; j++, ycnt++) {   printf(" ");  }  for (day =1; day <= mday[month - 1]; day++) {   if (youbi = 0)    printf("[%2d]", day);   else    printf(" %2d ", day);   ycnt++;   if (youbi > 7) {    printf("\n");    ycnt = 0;   }  }  return (0); } よろしくお願いします。

  • 生年月日関係の計算

    エクセルのバージョンは2002です。 2000/01/01のような生年月日のデータから、18年と1ヵ月後(年月のみ)のデータを作ります。 書式を変更するのではなく、新しいセルに打ち込みます。 なお、給与計算月(21日~翌20日)によるため、 たとえば1995/7/25なら2013/9      1995/7/15なら2013/8      1995/11/15なら2013/12            1995/11/25なら2014/1      1995/12/25なら2014/2  というように「給与計算月ベースの18年と1ヵ月後」のデータになるような式を作ります。 この条件で、L83のある生年月日を変換するのに =IF(MONTH(L83)+1=13,YEAR(L83)+19,IF(AND(DAY(L83)>20,MONTH(L83)+2=13),YEAR(L83)+19,YEAR(L83)+18))&"/"&IF(AND(DAY(L83)>20,MONTH(L83)+1=13),2,IF(AND(MONTH(L83)+2=13,DAY(L83)>20),1,IF(DAY(L83)>20,MONTH(L83)+2,IF(MONTH(L83)+1=13,1,MONTH(L83)+1)))) こんな式を強引に作ってうまく適用できたのですが、 もっとうまいやり方は無かったのだろうか・・・と思って質問しました。 やってみると意外に複雑です。 式を単純化できる方いらっしゃいましたら、後学のために教えてください。 よろしくお願いします

  • C言語で3次元配列を使い一年分のカレンダーを作成

    C言語課題で「三次元配列を定義して、与えられた年の1年間分のカレンダーを作成する」という課題があるのですが三次元配列を使い一年分のカレンダーがなかなか出来ません。 教えていただけるとありがたいです。 どうかよろしくお願いします!!!! 現状はこの状態です。 #pragma warning(disable:4996) #include <stdio.h> #define WEEK 6 enum M_LIST { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC, N_MONTH }; enum W_LIST { SUN, MON, TUE, WED, THU, FRI, SAT, N_WEEK }; char *weekday[] = { "日,月,火,水,木,金,土" }; //曜日 int mday[] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; //各月の日数 /*プロトタイプ宣言*/ int monthday(int year); void karenda(int total); /*メイン*/ void main(void) { int year; printf("西暦を出力"); scanf("%d", &year); //年度の出力 karenda(monthday(year)); } /*求める月の前月までの総日数*/ int monthday(int year) { int total = 0; /*求める年の前年までの総日数を求める*/ total = (((year - 1) * 365) + ((year - 1) / 4) - ((year - 1) / 100) + ((year - 1) / 400) + 1); /*うるう年の日数*/ if ((year % 4) == 0 && (year % 100) != 0 && (year % 400) == 0)mday[FEB] = 29; { } return total; } /*カレンダー*/ void karenda(int total) { int month, week, day; int box = total % 7; char cal[N_MONTH][WEEK][N_WEEK]; //3次元配列の宣言 for (month = 0; month < N_MONTH; month++) { printf("%d\n", (month + 1)); //月を入力 for (week = 0; week < WEEK; week++) { for (day = 0; day < N_WEEK; day++) { if (day < box){ printf(" "); } } } } } よろしくお願いします。

  • javaのカレンダー作成について

    コマンドライン引数で渡された6桁の数字をカレンダーに起こすプログラムを作成しています。 以下のように書きました。 ↓ public class Calendar { public static void main(String[] args) { java.util.Calendar cal = java.util.Calendar.getInstance(); int year = Integer.parseInt(args[0].substring(0, 4)); int month = Integer.parseInt(args[0].substring(4)); cal.set(java.util.Calendar.YEAR, year); cal.set(java.util.Calendar.MONTH, month - 1); cal.set(java.util.Calendar.DAY_OF_MONTH, 1); int week = cal.get(java.util.Calendar.DAY_OF_WEEK); //日曜始まり一週間のセット作成 int weekset = 0; if (week == cal.SUNDAY) { weekset = 0; } else if (week == cal.MONDAY) { weekset = 1; } else if (week == cal.TUESDAY) { weekset = 2; } else if (week == cal.WEDNESDAY) { weekset = 3; } else if (week == cal.THURSDAY) { weekset = 4; } else if (week == cal.FRIDAY) { weekset = 5; } else if (week == cal.SATURDAY) { weekset = 6; } //月末日 int lastDay = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH); //7日ごとに改行するカウンタ用意 int counter = 0; System.out.println( year + "年" + month + "月"); System.out.println(" 日 月 火 水 木 金 土"); //weekset分回す for (int i = 0; i < weekset; i++) { System.out.print(" "); counter ++; } //1日から月末日まで、カレンダーを表示する for (int day = 1 ; day <= lastDay; day ++) { if (day < 10) { System.out.print(" " + day + " "); } else { System.out.print( day + " "); } counter ++; if (counter == 7) { // 7日おきに改行する counter = 0; System.out.println(); } } } } きちんと動作してくれるのですが、2つ目のループ内の、 ************** for (int day = 1 ; day <= lastDay; day ++) { if (day < 10) { ●System.out.print(" " + day + " "); } else { ●System.out.print( day + " "); } ************** ●の部分の出力はループの外で一つに纏められるはずだと指摘されました。 dayの後ろの部分にだけなら、for文の前にString str = "";と宣言しておいて、 for (int day = 1 ; day <= lastDay; day ++) { str += " "; とすることで空白を付けられる気がしているのですが、前部分に空白を設定した上でまとめて出力する方法が分かりません。 お分かりになる方、どのようにすればよいのかご教授お願いいたします。 (また、上記の方法自体全く的外れということでしたらそれを含めてご教授お願いいたします・・・;;)

    • ベストアンサー
    • Java
  • C言語で3次元配列を使い一年分のカレンダーを作成

    カレンダーは完成したのですが曜日がズレてしまい綺麗に表示されません。どのように改善すれば良いのでしょうか?よろしくお願いします。 現状です #pragma warning(disable:4996) #include <stdio.h> #include <Windows.h> enum M_LIST { JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC, N_MONTH }; enum W_LIST { SUN, MON, TUE, WED, THU, FRI, SAT, N_WEEK }; int mday[] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; //各月の日数 char *weekday[] = { "日","月","火","水","木","金","土" }; //各曜日 /*プロトタイプ宣言*/ int monthday(int year); void Array(int total, char box[N_MONTH][N_WEEK][N_WEEK]); void karenda(char box[N_MONTH][N_WEEK][N_WEEK]); /*メイン*/ void main(void) { int year, total; char box[N_MONTH][N_WEEK][N_WEEK] = { 0 }; //3次元配列を宣言し0を入れる /*画面制御の初期化*/ COORD coord; HANDLE hStdout; hStdout = GetStdHandle(STD_OUTPUT_HANDLE); printf("西暦を入力"); scanf("%d", &year); //年度の入力 total = monthday(year); Array(total, box); karenda(box); } /*求める月の前月までの総日数*/ int monthday(int year) { int total = 0; /*求める年の前年までの総日数を求める*/ total = (((year - 1) * 365) + ((year - 1) / 4) - ((year - 1) / 100) + ((year - 1) / 400) + 1); /*うるう年の判定*/ if (((year % 4) == 0 && (year % 100) != 0) || (year % 400) == 0) { mday[FEB] = 29; } else { mday[FEB] = 28; } return total % 7; } /*カレンダーの配列*/ void Array(int total, char box[N_MONTH][N_WEEK][N_WEEK]) { int month, row, col, day; col = total; for (month = JAN; month < N_MONTH; month++) { row = 1; day = 1; while (day <= mday[month]) { box[month][row][col] = day; if (col > SAT) { //土曜までいったら次の週 row++; col = SUN; } day++; col++; } } } /*カレンダーの出力*/ void karenda(char box[N_MONTH][N_WEEK][N_WEEK]) { int month, week, day; for (month = JAN; month < N_MONTH; month++) { //月の出力 printf("%3d\n", month + 1); for (week = SUN; week < N_WEEK; week++) { for (day = SUN; day < N_WEEK; day++) { if (week == 0) { //曜日の出力 printf("%s", weekday[day]); } if (box[month][week][day] == 0) { //0なら空白 printf(" "); } else { printf("%3d", box[month][week][day]); } } printf("\n"); } printf("\n"); } } 今はこのような形で表示されます(空白は_で表しています) 日____月____火____水____木____金____土 ________1___2___3___4___5 6___7___8___9__10__11__12 13_14__15__16__17__18__19 20_21__22__23__24__25__26 27_28__29__30__31

  • Calendarクラスでエラーがでる

    こんにちは。 以下の単純なコードでエラーが出ます。 import java.util.Calendar; public class CalTest { public static void main(String args[]) { Calendar cal = cal.getInstance(); int year = 2002, month = 9, day = 19; cal.set(year,month,day); } } エラーは CalTest.java:6: 変数 cal は初期化されていない可能性があります。 Calendar cal = cal.getInstance(); です。使っているのはj2sdk1.4.0_01ですが、方法が変わったんでしょうか? 誰か分かる人がいたら教えてください。よろしくお願いします。

    • ベストアンサー
    • Java