###前提・実現したいこと
フォームからエクセルシートに入力値を転記するシステムを作っています。
フォームにスペースのみ入力されている場合はエラーメッセージを出力する処理を実装中に手詰まっております。Trim関数でスペースだけが入力されている場合はif内の条件に合わないため、何も処理が行われないようにしているはずですが、現時点ではフォームに入力された値すらシートに転記されない状態です。下記、ソースコードになります。どのように処理を記述すればうまくいくのかわかる方、ご教示願います。
###該当のソースコード
Private Sub CommandButton1_Click() If TextBox1.Value = "" Or TextBox2.Value = "" Or TextBox3.Value = "" Or TextBox4.Value = "" Or TextBox5.Value = "" Then MsgBox "空欄を埋めてください。" Else n = Worksheets("DB").Cells(Rows.Count, "A").End(xlUp).Row + 1 If Trim(TextBox1.Value) <> "" Then Range("A" & n).Value = TextBox1.Value End If n = Worksheets("DB").Cells(Rows.Count, "B").End(xlUp).Row + 1 If Trim(TextBox2.Value) <> "" Then Range("B" & n).Value = TextBox2.Value End If n = Worksheets("DB").Cells(Rows.Count, "C").End(xlUp).Row + 1 If Trim(TextBox3.Value) <> "" Then Range("C" & n).Value = TextBox3.Value End If n = Worksheets("DB").Cells(Rows.Count, "D").End(xlUp).Row + 1 If Trim(TextBox4.Value) <> "" Then Range("D" & n).Value = TextBox4.Value End If n = Worksheets("DB").Cells(Rows.Count, "E").End(xlUp).Row + 1 If Trim(TextBox5.Value) <> "" Then Range("E" & n).Value = TextBox5.Value End If TextBox1.Value = "" TextBox2.Value = "" TextBox3.Value = "" TextBox4.Value = "" TextBox5.Value = "" End If End Sub
###試したこと
Trim関数でif文を設置してみましたが、うまくいっておりません。
分かる方、ご教示お願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。