住所録を作成していますが、リストを選択しない場合10のテキストボックスで入力し 登録ボタンで指定範囲(P6:Y26)に入力するようにしていますがどうしても一番最初の行 に登録されてしまいます。リストボックスで行を選択すると登録&更新は可能ですが。 御指導願えませんでしょうか?(尚、リストボックスにはRowSource(P6:Y26)で表示し ています。) Windows7・SP1 Office2010 Private Sub CommandButton2_Click() Application.ScreenUpdating = False Application.Calculation = xlCalculationManual If fullname.Text = "" Then MsgBox "登録すべき内容がありません!", vbExclamation, "確認" Exit Sub End If Dim 選択行 As Integer Dim i As Integer If ListBox1.ListIndex = -1 Then 'リストが選択していなかったら(最初の行に登録される) i = Range("P65536").End(xlUp).Offset(1).Row Range("P" & i).Value = i - 5 Range("Q" & i).Value = fullname.Text Range("R" & i).Value = employeenumber.Text Range("S" & i).Value = fromaltitle.Text Range("T" & i).Value = company.Text Range("U" & i).Value = birthdate.Text Range("V" & i).Value = postalcode.Text Range("W" & i).Value = address.Text Range("X" & i).Value = tel.Text Range("Y" & i).Value = mobilephonenumber.Text Else i = ListBox1.ListIndex + 6 Range("P" & i).Value = i - 5 Range("Q" & i).Value = fullname.Text Range("R" & i).Value = employeenumber.Text Range("S" & i).Value = fromaltitle.Text Range("T" & i).Value = company.Text Range("U" & i).Value = birthdate.Text Range("V" & i).Value = postalcode.Text Range("W" & i).Value = address.Text Range("X" & i).Value = tel.Text Range("Y" & i).Value = mobilephonenumber.Text End If 'データをクリア With TextBox fullname.Text = "" employeenumber.Text = "" fromaltitle.Text = "" company.Text = "" birthdate.Text = "" postalcode.Text = "" address.Text = "" tel.Text = "" mobilephonenumber.Text = "" End With Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic End Sub
↧