"Another ScrollBar Question"
Hi Don
Glad the scroll bar code is working out for you. I have added the
requested line of code to set the activecell to the next blank cell in
column A, to do this all you need to do is set the value of the
scrollbar to whatever value you require, also I have looked at the
second question and have added some code to cover that which is the
same idea as putting the values in the textboxes just amended a little
to put the values in the cells, then I recall the userform initialise
event which will recalculate the range and select the next blank cell.
Option Explicit
Dim i As Integer
Dim LstCell As Integer
Dim SetRow As Integer
Dim Ctrl As MSForms.Control
Private Sub CmdBtn1_Click()
If TextBox1.Value = "" Then 'Check the user entered something
MsgBox "Enter A Name to Proceed" 'If not prompt them to do so
Exit Sub 'Stop the sub
End If
For i = 1 To 10 'Second number is the total No of textboxes
Set Ctrl = UF3.Controls("TextBox" & i) 'Select a textbox
ActiveCell.Value = Ctrl.Value 'Pass textbox value to
activecell
ActiveCell.Offset(0, 1).Select 'Iterate cell 1 to the right
Next 'Iterate textbox
UserForm_Initialize
End Sub
Private Sub ScrollBar1_Change()
SetRow = ScrollBar1.Value 'Pass scrollbar value to a variable
Range("A" & SetRow).Activate 'Select a row using that variable
For i = 1 To 10 'Second number is the total No of textboxes
Set Ctrl = UF3.Controls("TextBox" & i) 'Select a textbox
Ctrl.Value = ActiveCell.Value 'Show cell value in textbox
ActiveCell.Offset(0, 1).Activate 'Offset cell for the next
pass
Next 'Iterate textbox
Range("A" & SetRow).Activate 'Reselect the first column for when
you Save
End Sub
Private Sub UserForm_Initialize()
LstCell = [A65535].End(xlUp).Offset(1, 0).Row 'Find last used cell in
column A + 1
ScrollBar1.Min = 4 'Set Min and Max value to scroll bar
ScrollBar1.Max = LstCell
ScrollBar1.Value = LstCell 'Set scrollbar to the next empty cell
TextBox1.SetFocus 'Set the focus back to the first textbox
End Sub
I hope this clears things up for you
Steve
|