> 自分で作った物は保存をし次からの選択肢に加えることもできますか?
Sheet8のA2から下方向に保存していく(最後にブックを保存しなければ消える)
Private Sub CommandButton1_Click()
Dim buf As Variant, SRow As Variant
Dim i As Long, k As Long, j As Long: j = 0
Dim InputStr As String
Dim FRng As Range
Dim cCount As Long, LFlg As Boolean: LFlg = False
InputStr = Me.TextBox1.Value
If InputStr = "" Then Exit Sub
SRow = Split(InputStr, ",")
For i = LBound(SRow) To UBound(SRow)
If SRow(i) < 53 Or SRow(i) > 9950 Then
MsgBox SRow(i) & " は指定可能範囲から外れています。", vbCritical
Exit Sub
End If
Next
For cCount = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.List(cCount) = InputStr Then
LFlg = True
Exit For
End If
Next
If LFlg = False Then
With Sheets("Sheet8")
Set FRng = .Range(.Cells(2, "A"), .Cells(Rows.Count, "A").End(xlUp)).Find(What:=InputStr, LookIn:=xlValues, LookAt:=xlWhole)
If FRng Is Nothing Then
With .Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.NumberFormat = "@"
.Value = InputStr
Me.ListBox1.AddItem InputStr
End With
End If
End With
End If
With Sheets("Sheet8")
.Cells(4, "O").Resize(6003, 50).ClearContents
For k = 4 To 6003 Step UBound(SRow) - LBound(SRow) + 1
For i = LBound(SRow) To UBound(SRow)
buf = .Range(.Cells(SRow(i) + j - 50, "C"), .Cells(SRow(i) + j, "C")).Value
.Cells(k + i, "O").Resize(1, 50).Value = WorksheetFunction.Transpose(buf)
Next
j = j + 1
Next
End With
MsgBox "終了", vbInformation
Unload Me '←ダイアログを消さない場合いらない
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub ListBox1_Click()
Me.TextBox1.Value = Me.ListBox1.Value
End Sub
Private Sub UserForm_Initialize()
Dim i As Long
With Me.ListBox1
.AddItem "53,1050,2050,5050"
.AddItem "67,890,1210,560,458"
.AddItem "478,59,1506"
For i = 2 To Sheets("Sheet8").Cells(Rows.Count, "A").End(xlUp).Row
.AddItem Sheets("Sheet8").Cells(i, "A").Value
Next
End With
UserForm1.Caption = "行の選択/指定"
End Sub
お礼
こんばんはkkkkkm さん。このソースもNo. 13と同様にすればよろしいのでしょうか?