LoginSignup
1
3

More than 5 years have passed since last update.

Excel方眼で入力画面を作成する

Posted at

Excel方眼で入力画面を設計

EXCEL方眼で以下のような画面設計をします。テーブル(KJ_)にデータを保管するとします。
NC旋盤のマクロ番号をキーとします。

情報入力.png

データのロード、セーブマクロを定義する

テーブル名(R1N),テーブル行数(M),方眼位置(R2N)を引数として、マクロを定義します。
テーブルの項目と、方眼位置を一対一に対応させます。

Sub DGET(M, R1N, R2N)
    Range(R2N).Value = DI(Range(R1N), M)
End Sub

Sub DSET(M, R1N, R2N)
    Range(R1N).Offset(M - 1, 0).Resize(1, 1) = Range(R2N).Value
End Sub

Sub LOAD()
    If Not (ActiveSheet.Name Like "情報入力") Then Exit Sub

    Dim I: I = MI(Range("KJ_[O]"), Range("E2").Value)
    If I = "" Then Exit Sub

    Call START_MANUAL

    Call DGET(I, "KJ_[製品名]", "K2")
    Call DGET(I, "KJ_[材料]", "Z2")

    Call START_AUTO
End Sub

Sub SAVE()
    If Not (ActiveSheet.Name Like "情報入力") Then Exit Sub

    Dim I: I = MI(Range("KJ_[O]"), Range("E2").Value)
    If I = "" Then Exit Sub

    Call START_MANUAL

    Call DSET(I, "KJ_[製品名]", "K2")
    Call DSET(I, "KJ_[材料]", "Z2")

    Call START_AUTO
End Sub

ちらつきを無くすために、自動計算等を停止し、画面が更新した後に元に戻します。

Sub START_MANUAL()
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
End Sub

Sub START_AUTO()
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3