Declare a variable and then every time you move an item, increment the value of the variable by 1. So next time when you click the button to move the item, simply compare the value of the variable with the SpinButton's
Value. For example (Untested)
Dim nMoved As Long
Private Sub CommandButton1_Click()
If nMoved < (VAL(TextBox1.Text) + 1)
'
'~~> Code to move items from LB1 to LB2
'
nMoved = nMoved + 1
Else
MsgBox "Max items that can be moved from LB1 to LB2 reached."
End If
End Sub
FollowUp from Comments
You need to use .ListCount
in your case only if you are matching the items count in the LB against the TB. What I understood from your post is a user shouldn't be able to move more items into the LB than what is specified in the TB. Anyways, it seems that your query is sorted.
Regarding your 2nd comment.
You need to loop through the LB items using the code below and then exit the loop if the counter
is equal to the TB value. For example
For i = 0 To (ListBox1.ListCount - 1)
If i = (Val(TextBox1.Text) - 1) Then Exit For
'
'~~> Code to move items from LB1 to LB2
'
End If
Next i