論理:
Userform
を使用する代わりに を作成しますInputbox
。テキストを編集できるようにします。MsgBox
何も編集できないため、問題外です。
- ユーザーフォームを起動すると、
Worksheet_Change
そこでテキストを編集して、最終的にワークシートに書き戻すことができます。
基本的な準備:
VBA エディターを開き、ユーザーフォームを挿入します。TextBox
aと aを追加しCommandButton
ます。このように見えるかもしれません。

コード: これをユーザーフォームのコードに貼り付けます
Private Sub UserForm_Initialize()
With TextBox1
.MultiLine = True
.WordWrap = True
.ScrollBars = fmScrollBarsVertical
.EnterKeyBehavior = True
End With
End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
コード: これを関連するワークシートのコード領域に貼り付けます
'~~> Length of characters
Const nChars As Long = 2
Private Sub Worksheet_Change(ByVal Target As Range)
Dim sString As String
On Error GoTo Whoa
'~~> Check if there was a Paste/Autofill done
If Target.Cells.CountLarge > 1 Then Exit Sub
Application.EnableEvents = False
'~~> Check if the length is more than 2
If Len(Target.Value) > nChars Then
'~~> Set the userform's textbox text
With UserForm1
.TextBox1.Text = Target.Value
.Show
'~~> Get the value back to the sheet
Target.Value = .TextBox1.Text
End With
End If
Letscontinue:
Application.EnableEvents = True
Exit Sub
Whoa:
MsgBox Err.Description
Resume Letscontinue
End Sub
コードの実行:

テキストが入力されたら、関連する変更を加え ( 2 番目の文を新しい行に移動しました)、ボタンを押しUpdate
ます。
