Excelで販売管理を作成してみた。
UserForm1
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 |
Private WithEvents e As Application Sub e_SheetSelectionChange(ByVal w As Object, ByVal target As Range) If ToggleButton1.Value = False Then Exit Sub If ActiveSheet.Name <> "受注入力" Then Exit Sub r = target.Item(1).Row TextBox47.Text = r ' 行 TextBox19.Text = w.Cells(r, 1).Value ' 受注日 TextBox53.Text = w.Cells(r, 2).Value ' 得意先コード TextBox1.Text = w.Cells(r, 3).Value ' 得意先 TextBox52.Text = w.Cells(r, 4).Value ' 品目コード TextBox2.Text = w.Cells(r, 5).Value ' 品名 TextBox3.Text = w.Cells(r, 6).Value ' 型式・サイズ TextBox4.Text = w.Cells(r, 7).Value ' 工番 TextBox5.Text = w.Cells(r, 8).Value ' 数量 TextBox6.Text = w.Cells(r, 9).Value ' 単価 TextBox7.Text = w.Cells(r, 10).Value ' 金額 TextBox48.Text = w.Cells(r, 11).Value ' 注文番号 TextBox11.Text = w.Cells(r, 12).Value ' 納期 TextBox12.Text = w.Cells(r, 13).Value ' 備考 End Sub ' -------------------------------------------------------- ' 受注入力 ' -------------------------------------------------------- Private Sub CommandButton7_Click() ' クリア Call TextBoxClear Call TextBoxInitialize End Sub Private Sub CommandButton5_Click() ' 削除 If TextBox47.Text = "" Then MsgBox "対象の行が選択されていません。" Exit Sub End If ' 確認 If MsgBox("本当に削除しますか?", vbYesNo) = vbNo Then Exit Sub Set w = ThisWorkbook.Sheets("受注入力") Set t = ThisWorkbook.Sheets("更新削除履歴") ' 最終行取得 r = 2 Do While t.Cells(r, 1).Value <> "" r = r + 1 Loop target_row = r ' 履歴へ複写 r = TextBox47.Text t.Range("A" & target_row).Value = "削除" ' A列で最終行を把握しているので必須 t.Range("B" & target_row).Value = Format(Now, "yyyy/mm/dd") t.Range("C" & target_row & ":S" & target_row).Value = w.Range("A" & r & ":Q" & r).Value ' 削除 w.Rows(r).Delete TextBox47.Text = "" MsgBox "削除しました。" End Sub Private Sub CommandButton6_Click() ' 更新 ' チェック If TextBox47.Text = "" Then MsgBox "対象の行が選択されていません。" Exit Sub End If If TextBox19.Text = "" Or TextBox4.Text = "" Then MsgBox "入力が不足しています。" Exit Sub End If Set w = ThisWorkbook.Sheets("受注入力") Set t = ThisWorkbook.Sheets("更新削除履歴") ' 最終行取得 r = 2 Do While t.Cells(r, 1).Value <> "" r = r + 1 Loop target_row = r ' 履歴へ複写 r = TextBox47.Text t.Range("A" & target_row).Value = "更新" ' A列で最終行を把握しているので必須 t.Range("B" & target_row).Value = Format(Now, "yyyy/mm/dd") t.Range("C" & target_row & ":S" & target_row).Value = w.Range("A" & r & ":Q" & r).Value ' 書き込み r = TextBox47.Text w.Cells(r, 1).Value = TextBox19.Text ' 受注日 w.Cells(r, 2).Value = TextBox53.Text ' 得意先コード w.Cells(r, 3).Value = TextBox1.Text ' 得意先 w.Cells(r, 4).Value = TextBox52.Text ' 品目コード w.Cells(r, 5).Value = TextBox2.Text ' 品名 w.Cells(r, 6).Value = TextBox3.Text ' 型式・サイズ w.Cells(r, 7).Value = TextBox4.Text ' 工番 w.Cells(r, 8).Value = TextBox5.Text ' 数量 w.Cells(r, 9).Value = TextBox6.Text ' 単価 w.Cells(r, 10).Value = TextBox7.Text ' 金額 w.Cells(r, 11).Value = TextBox48.Text ' 注文番号 w.Cells(r, 12).Value = TextBox11.Text ' 納期 w.Cells(r, 13).Value = TextBox12.Text ' 備考 MsgBox "更新しました。" End Sub Private Sub CommandButton8_Click() ' 登録/工番固定 RegisterOrder (False) End Sub Private Sub CommandButton1_Click() ' 登録 RegisterOrder (True) End Sub Sub RegisterOrder(countup_serial) ' 未定の内容もあるため登録時は受注日と工番のみ必須 If TextBox19.Text = "" Or TextBox4.Text = "" Then MsgBox "入力が不足しています。" Exit Sub End If Set w = ThisWorkbook.Sheets("受注入力") ' 行末 r = 2 Do While w.Cells(r, 1).Value <> "" r = r + 1 Loop ' 書き込み w.Cells(r, 1).Value = TextBox19.Text ' 受注日 w.Cells(r, 2).Value = TextBox53.Text ' 得意先コード w.Cells(r, 3).Value = TextBox1.Text ' 得意先 w.Cells(r, 4).Value = TextBox52.Text ' 品目コード w.Cells(r, 5).Value = TextBox2.Text ' 品名 w.Cells(r, 6).Value = TextBox3.Text ' 型式 w.Cells(r, 7).Value = TextBox4.Text ' 工番 w.Cells(r, 8).Value = TextBox5.Text ' 数量 w.Cells(r, 9).Value = TextBox6.Text ' 単価 w.Cells(r, 10).Value = TextBox7.Text ' 金額 w.Cells(r, 11).Value = TextBox48.Text ' 注文番号 w.Cells(r, 12).Value = TextBox11.Text ' 納入日 w.Cells(r, 13).Value = TextBox12.Text ' 備考 ' 工番 Sheets("設定").Range("A2") = TextBox4.Text If countup_serial = True Then TextBox4.Text = CLng(TextBox4.Text) + 1 ' アクティブ w.Activate w.Range("A" & r & ":Q" & r).Select End Sub Private Sub MultiPage1_Change() End Sub Private Sub TextBox21_Change() ' 得意先マスタ ListBox1.Clear Set w = Sheets("得意先マスタ") r = 2 Do While w.Cells(r, 1).Value <> "" If InStr(LCase(w.Cells(r, 2).Value), LCase(TextBox21.Text)) > 0 Then ListBox1.AddItem ListBox1.List(ListBox1.ListCount - 1, 0) = w.Cells(r, 2).Value ListBox1.List(ListBox1.ListCount - 1, 1) = w.Cells(r, 1).Value ' 得意先コード End If r = r + 1 Loop End Sub Private Sub ListBox1_Click() ' 得意先マスタ TextBox1.Text = ListBox1.List(ListBox1.ListIndex, 0) TextBox53.Text = ListBox1.List(ListBox1.ListIndex, 1) End Sub Private Sub TextBox20_Change() ' 品名型式マスタ ListBox2.Clear Set w = Sheets("品名・型式マスタ") r = 2 Do While w.Cells(r, 1).Value <> "" If InStr(LCase(w.Cells(r, 2).Value & " " & w.Cells(r, 3).Value), LCase(TextBox20.Text)) > 0 Then ListBox2.AddItem ListBox2.List(ListBox2.ListCount - 1, 0) = w.Cells(r, 2).Value ListBox2.List(ListBox2.ListCount - 1, 1) = w.Cells(r, 3).Value ListBox2.List(ListBox2.ListCount - 1, 2) = w.Cells(r, 4).Value ListBox2.List(ListBox2.ListCount - 1, 3) = w.Cells(r, 1).Value ' 品目コード End If r = r + 1 Loop End Sub Private Sub ListBox2_Click() ' 品名型式マスタ TextBox2.Text = ListBox2.List(ListBox2.ListIndex, 0) TextBox3.Text = ListBox2.List(ListBox2.ListIndex, 1) TextBox6.Text = ListBox2.List(ListBox2.ListIndex, 2) TextBox52.Text = ListBox2.List(ListBox2.ListIndex, 3) ' 品目コード TotalAmount ' 単価が変わるため呼ぶ End Sub Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 数量 If IsNumeric(TextBox5.Text) Then TextBox5.Text = CDec(TextBox5.Text) Else TextBox5.Text = "" End If Call TotalAmount End Sub Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 単価 If IsNumeric(TextBox6.Text) Then TextBox6.Text = Format(CDec(TextBox6.Text), "#,###") Else TextBox6.Text = "" End If Call TotalAmount End Sub Private Sub TextBox7_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 金額 ' 手入力する場合 If IsNumeric(TextBox7.Text) Then TextBox7.Text = Format(CDec(TextBox7.Text), "#,###") Else TextBox7.Text = "" End If End Sub Sub TotalAmount() On Error GoTo exception TextBox7.Text = Format(CDec(TextBox5.Text) * CDec(TextBox6.Text), "#,###") ' 数量×単価 Exit Sub exception: TextBox7.Text = "" End Sub Private Sub TextBox19_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 受注日 If IsDate(TextBox19.Text) Then TextBox19.Text = Format(TextBox19.Text, "yyyy/mm/dd") Else TextBox19.Text = "" End If End Sub Private Sub TextBox11_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 納入日 If IsDate(TextBox11.Text) Then TextBox11.Text = Format(TextBox11.Text, "yyyy/mm/dd") Else TextBox11.Text = "" End If End Sub ' -------------------------------------------------------- ' 出荷予定表 ' -------------------------------------------------------- Private Sub CommandButton2_Click() If TextBox22.Text = "" Then Exit Sub If TextBox23.Text = "" Then Exit Sub Call create_shipping(TextBox22.Text, TextBox23.Text) End Sub Private Sub TextBox22_Exit(ByVal Cancel As MSForms.ReturnBoolean) If IsDate(TextBox22.Text) Then TextBox22.Text = Format(TextBox22.Text, "yyyy/mm/dd") Else TextBox22.Text = "" End If End Sub Private Sub TextBox23_Exit(ByVal Cancel As MSForms.ReturnBoolean) If IsDate(TextBox23.Text) Then TextBox23.Text = Format(TextBox23.Text, "yyyy/mm/dd") Else TextBox23.Text = "" End If End Sub ' -------------------------------------------------------- ' 工数入力 ' -------------------------------------------------------- Private Sub CommandButton3_Click() ' チェック chk = True If TextBox37.Text = "" Then chk = False ' 登録日 If TextBox54.Text = "" Then chk = False ' 得意先コード If TextBox32.Text = "" Then chk = False ' 得意先 If TextBox55.Text = "" Then chk = False ' 品名コード If TextBox31.Text = "" Then chk = False ' 品名 If TextBox30.Text = "" Then chk = False ' 型式・サイズ If TextBox29.Text = "" Then chk = False ' 工番 If ComboBox1.Text = "" Then chk = False ' 作業者 If TextBox33.Text = "" Then chk = False ' 作業日 If TextBox34.Text = "" Then chk = False ' 工数 If ComboBox2.Text = "" Then chk = False ' 作業内容 If False = chk Then MsgBox "入力に不足があります。" Exit Sub End If Set w = Sheets("工数入力") ' 行末 r = 2 Do While w.Cells(r, 1).Value <> "" r = r + 1 Loop ' 書き込み w.Cells(r, 1).Value = TextBox37.Text ' 登録日 w.Cells(r, 2).Value = TextBox54.Text ' 得意先コード w.Cells(r, 3).Value = TextBox32.Text ' 得意先 w.Cells(r, 4).Value = TextBox55.Text ' 品名コード w.Cells(r, 5).Value = TextBox31.Text ' 品名 w.Cells(r, 6).Value = TextBox30.Text ' 型式・サイズ w.Cells(r, 7).Value = TextBox29.Text ' 工番 w.Cells(r, 8).Value = ComboBox1.Text ' 作業者 w.Cells(r, 9).Value = TextBox33.Text ' 作業日 w.Cells(r, 10).Value = TextBox34.Text ' 工数 w.Cells(r, 12).Value = TextBox35.Text ' 備考 ' 作業内容 If ComboBox2.Text = "その他" Then w.Cells(r, 11).Value = TextBox36.Text If w.Cells(r, 11).Value = "" Then w.Cells(r, 11).Value = "その他" Else w.Cells(r, 11).Value = ComboBox2.Text End If ' アクティブ w.Activate w.Range("A" & r & ":L" & r).Select MsgBox "登録しました。" End Sub Private Sub ComboBox2_Change() If ComboBox2.Text = "その他" Then TextBox36.Enabled = True TextBox36.BackColor = vbWindowBackground Else TextBox36.Text = "" TextBox36.Enabled = False TextBox36.BackColor = vbMenuBar End If End Sub Private Sub ListBox3_Click() TextBox54.Text = ListBox3.List(ListBox3.ListIndex, 4) '得意先コード TextBox32.Text = ListBox3.List(ListBox3.ListIndex, 0) ' 得意先 TextBox55.Text = ListBox3.List(ListBox3.ListIndex, 5) ' 品名コード TextBox31.Text = ListBox3.List(ListBox3.ListIndex, 1) ' 品名 TextBox30.Text = ListBox3.List(ListBox3.ListIndex, 2) ' 型式・サイズ TextBox29.Text = ListBox3.List(ListBox3.ListIndex, 3) ' 工番 End Sub Private Sub TextBox33_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 作業日 If IsDate(TextBox33.Text) Then TextBox33.Text = Format(TextBox33.Text, "yyyy/mm/dd") Else TextBox33.Text = "" End If End Sub Private Sub TextBox34_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 工数 If IsNumeric(TextBox34.Text) Then TextBox34.Text = Format(TextBox34.Text, "#.#0") If CCur(TextBox34.Text) * 100 Mod 25 <> 0 Then TextBox34.Text = "" Else TextBox34.Text = "" End If End Sub ' -------------------------------------------------------- ' 請求書 ' -------------------------------------------------------- Private Sub CommandButton4_Click() ' 請求書発行 Call create_invoice End Sub Private Sub TextBox40_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 発行日 If IsDate(TextBox40.Text) Then TextBox40.Text = Format(TextBox40.Text, "yyyy/mm/dd") Else TextBox40.Text = "" End If End Sub Private Sub TextBox41_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 対象日(開始) If IsDate(TextBox41.Text) Then TextBox41.Text = Format(TextBox41.Text, "yyyy/mm/dd") Else TextBox41.Text = "" End If End Sub Private Sub TextBox46_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 対象日(終了) If IsDate(TextBox46.Text) Then TextBox46.Text = Format(TextBox46.Text, "yyyy/mm/dd") Else TextBox46.Text = "" End If End Sub Private Sub TextBox44_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 支払期限 If IsDate(TextBox44.Text) Then TextBox44.Text = Format(TextBox44.Text, "yyyy/mm/dd") Else TextBox44.Text = "" End If End Sub Private Sub ListBox4_Click() TextBox42.Text = ListBox4.List(ListBox4.ListIndex, 0) ' 得意先 TextBox50.Text = ListBox4.List(ListBox4.ListIndex, 1) ' 締日 TextBox51.Text = ListBox4.List(ListBox4.ListIndex, 2) ' 支払予定(経過日数) Call GetInvoiceTerm End Sub ' 得意先締日 OR 支払予定(経過日数) OR 締日(年月日) が変化したら請求期間の自動計算 Private Sub TextBox50_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 得意先締日 Call GetInvoiceTerm End Sub Private Sub TextBox51_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 支払予定(経過日数) Call GetInvoiceTerm End Sub Private Sub TextBox49_Exit(ByVal Cancel As MSForms.ReturnBoolean) ' 締日(年月日) Call GetInvoiceTerm ' フォーマット処理 If IsDate(TextBox49.Text) Then TextBox49.Text = Format(TextBox49.Text, "yyyy/mm/dd") Else TextBox49.Text = "" End If End Sub ' ここまで Private Sub TextBox27_Change() ' インクリメンタル検索 (品名型式マスタ) ListBox3.Clear Set w = Sheets("受注入力") r = 2 Do While w.Cells(r, 1).Value <> "" haystack = LCase(w.Cells(r, 2).Value & " " & w.Cells(r, 3).Value & " " & w.Cells(r, 4).Value & " " & w.Cells(r, 5).Value) needle = LCase(TextBox27.Text) If InStr(haystack, needle) > 0 Then ListBox3.AddItem ' 得意先、品名、型式、工番 ListBox3.List(ListBox3.ListCount - 1, 0) = w.Cells(r, 2).Value ListBox3.List(ListBox3.ListCount - 1, 1) = w.Cells(r, 3).Value ListBox3.List(ListBox3.ListCount - 1, 2) = w.Cells(r, 4).Value ListBox3.List(ListBox3.ListCount - 1, 3) = w.Cells(r, 5).Value End If r = r + 1 Loop ListBox3.ColumnCount = 4 End Sub Private Sub TextBox38_Change() ' インクリメンタル検索 (得意先マスタ) ListBox4.Clear Set w = Sheets("得意先マスタ") r = 2 Do While w.Cells(r, 1).Value <> "" If InStr(LCase(w.Cells(r, 2).Value), LCase(TextBox38.Text)) > 0 Then ListBox4.AddItem ListBox4.List(ListBox4.ListCount - 1, 0) = w.Cells(r, 2).Value ListBox4.List(ListBox4.ListCount - 1, 1) = w.Cells(r, 3).Value ListBox4.List(ListBox4.ListCount - 1, 2) = w.Cells(r, 4).Value End If r = r + 1 Loop End Sub Sub TextBoxClear() TextBox19.Text = "" ' 受注日 TextBox47.Text = "" ' 行 TextBox53.Text = "" ' 得意先コード TextBox1.Text = "" ' 得意先 TextBox52.Text = "" ' 品目コード TextBox2.Text = "" ' 品名 TextBox3.Text = "" ' 型式・サイズ TextBox4.Text = "" ' 工番 TextBox5.Text = "" ' 数量 TextBox6.Text = "" ' 単価 TextBox7.Text = "" ' 金額 TextBox11.Text = "" ' 納期 TextBox48.Text = "" ' 注文番号 TextBox12.Text = "" ' 備考 End Sub Sub TextBoxInitialize() TextBox19.Text = Format(Now, "yyyy/mm/dd") ' 受注日 TextBox4.Text = CLng(Sheets("設定").Range("A2")) + 1 ' 工番 End Sub Private Sub ToggleButton1_Click() If ActiveSheet.Name <> "受注入力" Then Sheets("受注入力").Activate If ToggleButton1.Value = True Then ' 更新/削除 可能状態 Call TextBoxClear ' Enabled CommandButton5.Enabled = True ' 削除 CommandButton6.Enabled = True ' 更新 CommandButton7.Enabled = False ' クリア CommandButton1.Enabled = False ' 登録 CommandButton8.Enabled = False ' 登録(固定) TextBox47.Enabled = True ' 行 TextBox4.Enabled = True ' 工番 Else ' 通常状態 Call TextBoxClear ' Enabled CommandButton5.Enabled = False ' 削除 CommandButton6.Enabled = False ' 更新 CommandButton7.Enabled = True ' クリア CommandButton1.Enabled = True ' 登録 CommandButton8.Enabled = True ' 登録(固定) TextBox47.Enabled = False ' 行 TextBox4.Enabled = False ' 工番 ' 初期値設定 Call TextBoxInitialize End If End Sub ' -------------------------------------------------------- ' Initialize ' -------------------------------------------------------- Private Sub UserForm_Initialize() Set e = Application ' 受注入力 -------------------------------------------------------- ' 品名型式マスタセット Set w = Sheets("品名・型式マスタ") r = 2 Do While w.Cells(r, 1).Value <> "" ListBox2.AddItem ListBox2.List(ListBox2.ListCount - 1, 0) = w.Cells(r, 2).Value ListBox2.List(ListBox2.ListCount - 1, 1) = w.Cells(r, 3).Value ListBox2.List(ListBox2.ListCount - 1, 2) = w.Cells(r, 4).Value ListBox2.List(ListBox2.ListCount - 1, 3) = w.Cells(r, 1).Value ' 品目コード r = r + 1 Loop ListBox2.ColumnCount = 2 ' 得意先マスタセット Set w = Sheets("得意先マスタ") r = 2 Do While w.Cells(r, 1).Value <> "" ListBox1.AddItem ListBox1.List(ListBox1.ListCount - 1, 0) = w.Cells(r, 2).Value ListBox1.List(ListBox1.ListCount - 1, 1) = w.Cells(r, 1).Value ' 得意先コード r = r + 1 Loop ' 受注日 TextBox19.Text = Format(Now, "yyyy/mm/dd") ' 工番 serial = CLng(Sheets("設定").Range("A2")) + 1 TextBox4.Text = serial ' 工数入力 -------------------------------------------------------- ' 登録日 TextBox37.Text = Format(Now, "yyyy/mm/dd") ' 品目型式セット Set w = Sheets("受注入力") r = 2 Do While w.Cells(r, 1).Value <> "" ListBox3.AddItem ' 得意先、品名、型式・サイズ、工番 ListBox3.List(ListBox3.ListCount - 1, 0) = w.Cells(r, 3).Value ListBox3.List(ListBox3.ListCount - 1, 1) = w.Cells(r, 5).Value ListBox3.List(ListBox3.ListCount - 1, 2) = w.Cells(r, 6).Value ListBox3.List(ListBox3.ListCount - 1, 3) = w.Cells(r, 7).Value ListBox3.List(ListBox3.ListCount - 1, 4) = w.Cells(r, 2).Value ' 得意先コード ListBox3.List(ListBox3.ListCount - 1, 5) = w.Cells(r, 4).Value ' 品目コード r = r + 1 Loop ListBox3.ColumnCount = 4 ' 作業者マスタセット Set w = Sheets("作業者マスタ") r = 2 Do While w.Cells(r, 1).Value <> "" ComboBox1.AddItem w.Cells(r, 1).Value r = r + 1 Loop ' 作業内容マスタセット Set w = Sheets("作業内容マスタ") r = 2 Do While w.Cells(r, 1).Value <> "" ComboBox2.AddItem w.Cells(r, 1).Value r = r + 1 Loop ' 請求書 -------------------------------------------------------- ' 発行日 TextBox40.Text = Format(Now, "yyyy/mm/dd") ' 得意先マスタセット Set w = Sheets("得意先マスタ") r = 2 Do While w.Cells(r, 1).Value <> "" ListBox4.AddItem ListBox4.List(ListBox4.ListCount - 1, 0) = w.Cells(r, 2).Value ListBox4.List(ListBox4.ListCount - 1, 1) = w.Cells(r, 3).Value ListBox4.List(ListBox4.ListCount - 1, 2) = w.Cells(r, 4).Value r = r + 1 Loop ' 請求番号 serial = CLng(Sheets("設定").Range("C2")) + 1 TextBox43.Text = serial End Sub |
出荷予定表
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
Sub create_shipping(start_day, end_day) ' 出荷予定表 Set f = Sheets("受注入力") Set t = Sheets("出荷予定表") ' リセット t.Rows("2:5000").Delete ' メイン r = 2 rr = 2 Do While f.Cells(r, 1).Value <> "" If CDate(f.Cells(r, 12).Value) >= start_day And CDate(f.Cells(r, 12).Value) <= end_day Then t.Cells(rr, 1).Value = f.Cells(r, 3).Value ' 得意先 t.Cells(rr, 2).Value = f.Cells(r, 5).Value ' 品名 t.Cells(rr, 3).Value = f.Cells(r, 6).Value ' 型式・サイズ t.Cells(rr, 4).Value = f.Cells(r, 7).Value ' 工番 t.Cells(rr, 5).Value = f.Cells(r, 8).Value ' 数量 t.Cells(rr, 6).Value = f.Cells(r, 11).Value ' 注文番号 t.Cells(rr, 7).Value = f.Cells(r, 12).Value ' 納期 rr = rr + 1 End If r = r + 1 Loop ' 罫線 t.Range("A1:G" & rr - 1).Borders.LineStyle = True ' 印刷範囲 (プリンター関係のエラーは無視) On Error Resume Next t.PageSetup.PrintArea = "A1:G" & rr - 1 On Error GoTo 0 ' アクティブ t.Activate t.Range("A1:G" & rr - 1).Select End Sub |
請求期間
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
Sub GetInvoiceTerm() ' チェック If False = IsDate(UserForm1.TextBox49.Text) Then Exit Sub If False = IsNumeric(UserForm1.TextBox50.Text) Then Exit Sub If False = IsNumeric(UserForm1.TextBox51.Text) Then Exit Sub current_date = CDate(UserForm1.TextBox49.Text) ' 今回の締日 master_closing_date = CInt(UserForm1.TextBox50.Text) ' 得意先締日 payment_duration = CInt(UserForm1.TextBox51.Text) ' 支払予定(経過日数) start_day = "" end_day = "" If master_closing_date <> "30" Then ' 末締以外 If CInt(Day(current_date)) > CInt(master_closing_date) Then tmp = DateAdd("m", 1, current_date) start_day = Year(current_date) & "/" & Month(current_date) & "/" & master_closing_date + 1 end_day = Year(tmp) & "/" & Month(tmp) & "/" & master_closing_date Else tmp = DateAdd("m", -1, current_date) start_day = Year(tmp) & "/" & Month(tmp) & "/" & master_closing_date + 1 end_day = Year(current_date) & "/" & Month(current_date) & "/" & master_closing_date End If Else ' 末締の場合 start_day = Year(current_date) & "/" & Month(current_date) & "/1" end_day = Year(current_date) & "/" & Month(current_date) & "/" & GetLastDay(current_date) End If If False = IsDate(start_day) Or False = IsDate(end_day) Then ' 得意先締日の値からstart_day、end_dayが有効な日付にならなかった場合 UserForm1.TextBox41.Text = "" UserForm1.TextBox46.Text = "" UserForm1.TextBox44.Text = "" Exit Sub End If UserForm1.TextBox41.Text = Format(CDate(start_day), "yyyy/mm/dd") UserForm1.TextBox46.Text = Format(CDate(end_day), "yyyy/mm/dd") ' 支払期限算出-------------------------------------------------------- ' 支払予定(経過日数)を30で割り×月、余り×日 m = payment_duration / 30 d = payment_duration Mod 30 If True = IsLastDay(CDate(end_day)) Then ' end_dayが月末の場合は指定した月数を加算し月末にする。 tmp1 = DateAdd("m", m, CDate(end_day)) tmp1 = CDate(Year(tmp1) & "/" & Month(tmp1) & "/" & GetLastDay(tmp1)) tmp2 = DateAdd("d", d, tmp1) Else ' end_dayが月末以外 tmp1 = DateAdd("m", m, CDate(end_day)) tmp2 = DateAdd("d", d, tmp1) End If UserForm1.TextBox44.Text = Format(tmp2, "yyyy/mm/dd") End Sub Function IsLastDay(target) ' 渡された日付が月末かどうか ' 呼出側で日付型か確認済 If Day(target) = GetLastDay(target) Then IsLastDay = True Else IsLastDay = False End If End Function Function GetLastDay(target) ' 渡された日付の月の月末を取得 ' 呼出側で日付型か確認済 GetLastDay = Day(DateAdd("d", -1, Year(DateAdd("m", 1, target)) & "/" & Month(DateAdd("m", 1, target)) & "/1")) End Function |
請求書
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
Sub create_invoice() ' チェック chk = True If UserForm1.TextBox40.Text = "" Then chk = False ' 発行日 If UserForm1.TextBox43.Text = "" Then chk = False ' 請求番号 'If UserForm1.TextBox49.Text = "" Then chk = False ' 締日 ' 手動で請求期限を入力する場合、不要なため+自動計算が発火しないため If UserForm1.TextBox42.Text = "" Then chk = False ' 得意先 If UserForm1.TextBox50.Text = "" Then chk = False ' 得意先締日 If UserForm1.TextBox51.Text = "" Then chk = False ' 支払予定 If UserForm1.TextBox41.Text = "" Then chk = False ' 請求期間・開始 If UserForm1.TextBox46.Text = "" Then chk = False ' 請求期間・終了 If UserForm1.TextBox44.Text = "" Then chk = False ' 支払期限 If False = chk Then MsgBox "入力に不足があります。" Exit Sub End If Set w = ThisWorkbook.Sheets("受注入力") ' 行数カウント r = 2 c = 1 Do While w.Cells(r, 1).Value <> "" ' 受注日で最終行取得 If w.Cells(r, 3).Value = UserForm1.TextBox42.Text Then ' 得意先マッチ ' 請求期間マッチ(受注入力の計上日を利用) If CDate(w.Cells(r, 16).Value) >= CDate(UserForm1.TextBox41.Text) And _ CDate(w.Cells(r, 16).Value) <= CDate(UserForm1.TextBox46.Text) Then If c > 75 Then ' 最大行数 MsgBox "行数が多いため中止します。" Exit Sub End If c = c + 1 End If End If r = r + 1 Loop ' ヘッダ ThisWorkbook.Sheets("請求書").Range("A2").Value = UserForm1.TextBox42.Text & " 御中" ThisWorkbook.Sheets("請求書").Range("L3").Value = " 伝票番号:" & UserForm1.TextBox43.Text ThisWorkbook.Sheets("請求書").Range("L4").Value = " 発行日:" & UserForm1.TextBox40.Text ThisWorkbook.Sheets("請求書").Range("P6").Value = UserForm1.TextBox44.Text ' 支払期限 ThisWorkbook.Sheets("請求書").Range("P7").Value = Format(UserForm1.TextBox41.Text, "yyyy/mm/dd") & "~" & Format(UserForm1.TextBox46.Text, "yyyy/mm/dd") ' 請求期間 ' 書き込み r = 2 c = 1 Do While w.Cells(r, 1).Value <> "" ' 受注日で最終行取得 If w.Cells(r, 3).Value = UserForm1.TextBox42.Text Then ' 得意先マッチ ' 請求期間マッチ If CDate(w.Cells(r, 16).Value) >= CDate(UserForm1.TextBox41.Text) And _ CDate(w.Cells(r, 16).Value) <= CDate(UserForm1.TextBox46.Text) Then If c <= 15 Then ThisWorkbook.Sheets("請求書").Cells(c + 18, 1).Value = w.Cells(r, 15).Value ' 納品日 ThisWorkbook.Sheets("請求書").Cells(c + 18, 2).Value = w.Cells(r, 14).Value ' 納品番号 ThisWorkbook.Sheets("請求書").Cells(c + 18, 3).Value = w.Cells(r, 11).Value ' 注文番号 ThisWorkbook.Sheets("請求書").Cells(c + 18, 4).Value = w.Cells(r, 5).Value & " " & w.Cells(r, 6).Value ' 品名 ThisWorkbook.Sheets("請求書").Cells(c + 18, 6).Value = w.Cells(r, 8).Value ' 数量 ThisWorkbook.Sheets("請求書").Cells(c + 18, 7).Value = w.Cells(r, 9).Value ' 単価 ThisWorkbook.Sheets("請求書").Cells(c + 18, 9).Value = w.Cells(r, 10).Value ' 金額 ThisWorkbook.Sheets("請求書").Cells(c + 18, 11).Value = w.Cells(r, 13).Value ' 備考 ThisWorkbook.Sheets("請求書").Cells(c + 18, 13).Value = w.Cells(r, 7).Value ' 工番 w.Cells(r, 17).Value = UserForm1.TextBox43.Text ' 請求番号 ElseIf c >= 16 And c <= 45 Then ThisWorkbook.Sheets("請求書2").Cells(c - 13, 1).Value = w.Cells(r, 15).Value ' 納品日 ThisWorkbook.Sheets("請求書2").Cells(c - 13, 2).Value = w.Cells(r, 14).Value ' 納品番号 ThisWorkbook.Sheets("請求書2").Cells(c - 13, 3).Value = w.Cells(r, 11).Value ' 注文番号 ThisWorkbook.Sheets("請求書2").Cells(c - 13, 4).Value = w.Cells(r, 5).Value & " " & w.Cells(r, 6).Value ' 品名 ThisWorkbook.Sheets("請求書2").Cells(c - 13, 6).Value = w.Cells(r, 8).Value ' 数量 ThisWorkbook.Sheets("請求書2").Cells(c - 13, 7).Value = w.Cells(r, 9).Value ' 単価 ThisWorkbook.Sheets("請求書2").Cells(c - 13, 9).Value = w.Cells(r, 10).Value ' 金額 ThisWorkbook.Sheets("請求書2").Cells(c - 13, 11).Value = w.Cells(r, 13).Value ' 備考 ThisWorkbook.Sheets("請求書2").Cells(c - 13, 13).Value = w.Cells(r, 7).Value ' 工番 w.Cells(r, 17).Value = UserForm1.TextBox43.Text ' 請求番号 p2_total = p2_total + CCur(w.Cells(r, 10).Value) ElseIf c >= 46 And c <= 75 Then ThisWorkbook.Sheets("請求書3").Cells(c - 43, 1).Value = w.Cells(r, 15).Value ' 納品日 ThisWorkbook.Sheets("請求書3").Cells(c - 43, 2).Value = w.Cells(r, 14).Value ' 納品番号 ThisWorkbook.Sheets("請求書3").Cells(c - 43, 3).Value = w.Cells(r, 11).Value ' 注文番号 ThisWorkbook.Sheets("請求書3").Cells(c - 43, 4).Value = w.Cells(r, 5).Value & " " & w.Cells(r, 6).Value ' 品名 ThisWorkbook.Sheets("請求書3").Cells(c - 43, 6).Value = w.Cells(r, 8).Value ' 数量 ThisWorkbook.Sheets("請求書3").Cells(c - 43, 7).Value = w.Cells(r, 9).Value ' 単価 ThisWorkbook.Sheets("請求書3").Cells(c - 43, 9).Value = w.Cells(r, 10).Value ' 金額 ThisWorkbook.Sheets("請求書3").Cells(c - 43, 11).Value = w.Cells(r, 13).Value ' 備考 ThisWorkbook.Sheets("請求書3").Cells(c - 43, 13).Value = w.Cells(r, 7).Value ' 工番 w.Cells(r, 17).Value = UserForm1.TextBox43.Text ' 請求番号 p3_total = p3_total + CCur(w.Cells(r, 10).Value) End If c = c + 1 End If End If r = r + 1 Loop ' ヘッダー(金額) ThisWorkbook.Sheets("請求書").Range("P3").Value = p2_total ThisWorkbook.Sheets("請求書").Range("P4").Value = p3_total ' フッター(ページ数の有無で複写を判断) If c <= 15 Then ThisWorkbook.Sheets("請求書").Range("M35").Value = "P1/1" ThisWorkbook.Sheets("請求書2").Range("M34").Value = "" ThisWorkbook.Sheets("請求書3").Range("M34").Value = "" ElseIf c >= 16 And c <= 45 Then ThisWorkbook.Sheets("請求書").Range("M35").Value = "P1/2" ThisWorkbook.Sheets("請求書2").Range("M34").Value = "P2/2" ThisWorkbook.Sheets("請求書3").Range("M34").Value = "" ElseIf c >= 46 And c <= 75 Then ThisWorkbook.Sheets("請求書").Range("M35").Value = "P1/3" ThisWorkbook.Sheets("請求書2").Range("M34").Value = "P2/3" ThisWorkbook.Sheets("請求書3").Range("M34").Value = "P3/3" End If ' 計上履歴 Set w = ThisWorkbook.Sheets("計上履歴") ' 行末 r = 2 Do While w.Cells(r, 1).Value <> "" r = r + 1 Loop w.Cells(r, 1).Value = UserForm1.TextBox40.Text ' 発行日 w.Cells(r, 2).Value = UserForm1.TextBox43.Text ' 請求番号 w.Cells(r, 3).Value = UserForm1.TextBox44.Text ' 支払期限 w.Cells(r, 4).Value = Format(UserForm1.TextBox41.Text, "yyyy/mm/dd") & "~" & Format(UserForm1.TextBox46.Text, "yyyy/mm/dd") ' 請求期間 w.Cells(r, 5).Value = UserForm1.TextBox42.Text ' 得意先 w.Cells(r, 6).Value = ThisWorkbook.Sheets("請求書").Range("B12").Value ' 合計 w.Cells(r, 7).Value = ThisWorkbook.Sheets("請求書").Range("B13").Value ' 消費税8% w.Cells(r, 8).Value = ThisWorkbook.Sheets("請求書").Range("B14").Value ' 消費税10% w.Cells(r, 9).Value = ThisWorkbook.Sheets("請求書").Range("B15").Value ' 請求額 ' シートコピー Call copy_invoice(UserForm1.TextBox43.Text) Call reset_invoice ' 請求番号更新 ThisWorkbook.Sheets("設定").Range("C2") = UserForm1.TextBox43.Text UserForm1.TextBox43.Text = CLng(UserForm1.TextBox43.Text) + 1 End Sub Sub copy_invoice(order) ' ブックが開いているか opened = False For Each wb In Workbooks If wb.Name = "請求書.xlsx" Then opened = True Next ' 開いていない場合開く If opened = False Then Workbooks.Open ThisWorkbook.Path & "\請求書.xlsx" ' 重複チェック Set target = Workbooks("請求書.xlsx") exists = False For Each w In target.Sheets If w.Name = CStr(order) & "_1" Then exists = True If w.Name = CStr(order) & "_2" Then exists = True If w.Name = CStr(order) & "_3" Then exists = True Next If exists = True Then MsgBox "既に請求書が存在します。削除後、もう一度実行してください。" Exit Sub End If ' シートのコピー Set target = Workbooks("請求書.xlsx") If ThisWorkbook.Sheets("請求書").Range("M35").Value <> "" Then ThisWorkbook.Sheets("請求書").Copy After:=target.Sheets(target.Sheets.Count) target.Sheets("請求書").Name = order & "_1" End If If ThisWorkbook.Sheets("請求書2").Range("M34").Value <> "" Then ThisWorkbook.Sheets("請求書2").Copy After:=target.Sheets(target.Sheets.Count) target.Sheets("請求書2").Name = order & "_2" End If If ThisWorkbook.Sheets("請求書3").Range("M34").Value <> "" Then ThisWorkbook.Sheets("請求書3").Copy After:=target.Sheets(target.Sheets.Count) target.Sheets("請求書3").Name = order & "_3" End If End Sub Sub reset_invoice() Set w = ThisWorkbook.Sheets("請求書") w.Range("A2").Value = "御中" w.Range("M3").Value = "伝票番号:" w.Range("M4").Value = "発行日:" w.Range("P3").Value = "" w.Range("P4").Value = "" w.Range("P6").Value = "" w.Range("P7").Value = "" w.Range("M35").Value = "P. 1/1" For r = 19 To 33 w.Cells(r, 1).Value = "" w.Cells(r, 2).Value = "" w.Cells(r, 3).Value = "" w.Cells(r, 4).Value = "" w.Cells(r, 6).Value = "" w.Cells(r, 7).Value = "" w.Cells(r, 9).Value = "" w.Cells(r, 11).Value = "" w.Cells(r, 13).Value = "" Next Set w = ThisWorkbook.Sheets("請求書2") w.Range("M34").Value = "P. 2/2" For r = 3 To 32 w.Cells(r, 1).Value = "" w.Cells(r, 2).Value = "" w.Cells(r, 3).Value = "" w.Cells(r, 4).Value = "" w.Cells(r, 6).Value = "" w.Cells(r, 7).Value = "" w.Cells(r, 9).Value = "" w.Cells(r, 11).Value = "" w.Cells(r, 13).Value = "" Next Set w = ThisWorkbook.Sheets("請求書3") w.Range("M34").Value = "P. 3/3" For r = 3 To 32 w.Cells(r, 1).Value = "" w.Cells(r, 2).Value = "" w.Cells(r, 3).Value = "" w.Cells(r, 4).Value = "" w.Cells(r, 6).Value = "" w.Cells(r, 7).Value = "" w.Cells(r, 9).Value = "" w.Cells(r, 11).Value = "" w.Cells(r, 13).Value = "" Next End Sub |
設定
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
Sub test() Application.CommandBars("cell").Reset End Sub Sub reset_right_click() For i = 1 To 3 Application.CommandBars("cell").Controls("フォーム表示").Delete Application.CommandBars("cell").Controls("納品書作成").Delete Next End Sub Sub auto_close() On Error Resume Next Call reset_right_click End Sub Sub auto_open() On Error Resume Next Call reset_right_click With Application.CommandBars("cell").Controls.Add .OnAction = "show_form" .Caption = "フォーム表示" End With With Application.CommandBars("cell").Controls.Add .OnAction = "create_delivery_note" .Caption = "納品書作成" End With ' フィルタ解除 For Each s In Worksheets s.AutoFilterMode = False Next ' 起動 Call set_style ' アクティブ Sheets("設定").Activate End Sub Sub show_form() If ActiveWorkbook.Name <> ThisWorkbook.Name Then Exit Sub UserForm1.Show End Sub Sub set_style() Set w = Sheets("受注入力") w.Columns("A").NumberFormatLocal = "yyyy/mm/dd" w.Columns("B").NumberFormatLocal = "@" w.Columns("C").NumberFormatLocal = "@" w.Columns("D").NumberFormatLocal = "@" w.Columns("E").NumberFormatLocal = "@" w.Columns("F").NumberFormatLocal = "@" w.Columns("G").NumberFormatLocal = "@" w.Columns("H").NumberFormatLocal = "0" w.Columns("I").NumberFormatLocal = "#,##0" w.Columns("J").NumberFormatLocal = "#,##0" w.Columns("K").NumberFormatLocal = "@" w.Columns("L").NumberFormatLocal = "yyyy/mm/dd" w.Columns("M").NumberFormatLocal = "@" w.Columns("N").NumberFormatLocal = "@" w.Columns("O").NumberFormatLocal = "yyyy/mm/dd" w.Columns("P").NumberFormatLocal = "yyyy/mm/dd" w.Columns("Q").NumberFormatLocal = "@" ' -------------------------------------------------------- Set w = Sheets("更新削除履歴") w.Columns("A").NumberFormatLocal = "@" w.Columns("B").NumberFormatLocal = "yyyy/mm/dd" w.Columns("C").NumberFormatLocal = "yyyy/mm/dd" w.Columns("D").NumberFormatLocal = "@" w.Columns("E").NumberFormatLocal = "@" w.Columns("F").NumberFormatLocal = "@" w.Columns("G").NumberFormatLocal = "@" w.Columns("H").NumberFormatLocal = "@" w.Columns("I").NumberFormatLocal = "@" w.Columns("J").NumberFormatLocal = "0" w.Columns("K").NumberFormatLocal = "#,##0" w.Columns("L").NumberFormatLocal = "#,##0" w.Columns("M").NumberFormatLocal = "@" w.Columns("N").NumberFormatLocal = "yyyy/mm/dd" w.Columns("O").NumberFormatLocal = "@" w.Columns("P").NumberFormatLocal = "@" w.Columns("Q").NumberFormatLocal = "yyyy/mm/dd" w.Columns("R").NumberFormatLocal = "yyyy/mm/dd" w.Columns("S").NumberFormatLocal = "@" ' -------------------------------------------------------- Set w = Sheets("出荷予定表") w.Columns("A").NumberFormatLocal = "@" w.Columns("B").NumberFormatLocal = "@" w.Columns("C").NumberFormatLocal = "@" w.Columns("D").NumberFormatLocal = "0" w.Columns("E").NumberFormatLocal = "0" w.Columns("F").NumberFormatLocal = "@" w.Columns("G").NumberFormatLocal = "yyyy/mm/dd" ' -------------------------------------------------------- Set w = Sheets("計上履歴") w.Columns("A").NumberFormatLocal = "yyyy/mm/dd" w.Columns("B").NumberFormatLocal = "0" w.Columns("C").NumberFormatLocal = "yyyy年mm月dd日" w.Columns("D").NumberFormatLocal = "@" w.Columns("E").NumberFormatLocal = "@" w.Columns("F").NumberFormatLocal = "#,##0" w.Columns("G").NumberFormatLocal = "#,##0" w.Columns("H").NumberFormatLocal = "#,##0" w.Columns("I").NumberFormatLocal = "#,##0" ' -------------------------------------------------------- Set w = Sheets("工数入力") w.Columns("A").NumberFormatLocal = "yyyy/mm/dd" w.Columns("B").NumberFormatLocal = "@" w.Columns("C").NumberFormatLocal = "@" w.Columns("D").NumberFormatLocal = "@" w.Columns("E").NumberFormatLocal = "@" w.Columns("F").NumberFormatLocal = "@" w.Columns("G").NumberFormatLocal = "@" w.Columns("H").NumberFormatLocal = "@" w.Columns("I").NumberFormatLocal = "yyyy/mm/dd" w.Columns("J").NumberFormatLocal = "0.00" w.Columns("K").NumberFormatLocal = "@" w.Columns("L").NumberFormatLocal = "@" End Sub |
納品書
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
Sub create_delivery_note() ' 納品書作成 If ActiveWorkbook.Name <> ThisWorkbook.Name Then Exit Sub Set w = ActiveSheet ' シート名チェック If w.Name <> "受注入力" Then MsgBox "受注入力シートで実行してください。" Exit Sub End If '選択範囲を一意の行へ Set dic = CreateObject("scripting.dictionary") For Each r In Selection If Not dic.exists(r.Row) Then dic.Add r.Row, "" Next ReDim selected_rows(dic.Count - 1) k = dic.keys For i = 0 To dic.Count - 1 selected_rows(i) = k(i) Next i selected_rows_count = dic.Count ' 選択行数チェック If selected_rows_count > 15 Then MsgBox "選択できるのは15行までです。" Exit Sub End If ' 得意先、納品日チェック For Each r In selected_rows If w.Cells(r, 15).Value = "" Then MsgBox "納品日が空白です。" Exit Sub End If If w.Cells(r, 15).Value <> w.Cells(selected_rows(0), 15).Value Then MsgBox "複数の納品日が選択されてます。" Exit Sub End If If w.Cells(r, 3).Value <> w.Cells(selected_rows(0), 3).Value Then MsgBox "複数の得意先が選択されてます。" Exit Sub End If Next ' 重複、納品番号 For Each r In selected_rows If w.Cells(r, 14).Value <> "" Then MsgBox r & "行目は既に発行済です。注意してください。" End If Next ' 納品書 -------------------------------------------------------- ' 伝票番号 order = CLng(Sheets("設定").Range("B2").Value) + 1 Sheets("設定").Range("B2").Value = order ' 書き込み With ThisWorkbook.Sheets("納品書") rr = 13 For Each r In selected_rows If r = selected_rows(0) Then ' 選択行の一番上の行を利用(一度だけ書き込み) .Range("J2").Value = "伝票番号:" & order ' 納品番号 .Range("J3").Value = "納品日:" & Format(w.Cells(r, 15).Value, "yyyy年mm月dd日") ' 納品日 .Range("A2").Value = w.Cells(r, 3).Value & " 御中" ' 得意先 End If .Cells(rr, 1).Value = w.Cells(r, 11).Value ' 注文番号 .Cells(rr, 3).Value = w.Cells(r, 5).Value & " " & w.Cells(r, 6).Value ' 品名 .Cells(rr, 5).Value = w.Cells(r, 8).Value ' 数量 .Cells(rr, 6).Value = w.Cells(r, 9).Value ' 単価 .Cells(rr, 8).Value = w.Cells(r, 10).Value ' 金額 .Cells(rr, 9).Value = w.Cells(r, 13).Value ' 備考 .Cells(rr, 11).Value = w.Cells(r, 7).Value ' 工番 ' 受注入力シート書込 w.Cells(r, 14).Value = "" & order ' 納品番号 rr = rr + 1 Next End With ' アクティブ w.Activate ' シートコピー -------------------------------------------------------- opened = False ' ブックが開いているか For Each wb In Workbooks If wb.Name = "納品書.xlsx" Then opened = True Next ' 開いていない場合開く 'On Error GoTo exception If opened = False Then Workbooks.Open ThisWorkbook.Path & "\納品書.xlsx" 'On Error GoTo 0 ' シートのコピー Set b = Workbooks("納品書.xlsx") ThisWorkbook.Sheets("納品書").Copy After:=b.Sheets(b.Sheets.Count) ' シートが存在しているかどうか、存在していたらsuffix exists = False For Each w In b.Sheets If w.Name = CStr(order) Then exists = True Next If exists = False Then b.Sheets("納品書").Name = order Else b.Sheets("納品書").Name = order & "(2)" End If Call reset_delivery Exit Sub exception: Call reset_delivery MsgBox "納品書.xlsxが存在しません。" End Sub Sub reset_delivery() Set w = ThisWorkbook.Sheets("納品書") w.Range("J2").Value = "伝票番号:" w.Range("J3").Value = "納品日:" w.Range("A2").Value = "御中" For r = 13 To 27 w.Cells(r, 1).Value = "" w.Cells(r, 3).Value = "" w.Cells(r, 5).Value = "" w.Cells(r, 6).Value = "" w.Cells(r, 8).Value = "" w.Cells(r, 9).Value = "" w.Cells(r, 11).Value = "" Next End Sub |