View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
owlnevada owlnevada is offline
external usenet poster
 
Posts: 44
Default Userform to increment line item numbers with textboxes-spinbuttons

I use the following code with a userform to renumber line item numbers that
get changed. My UF has two spinbuttons with two textboxes that update each
other for a starting and ending line item number. I need help with just this
part that looks at those two entries to change and increment the line number
by one from the starting line no. to the ending line number. These can be
something like "1" to "8" or "9" to "16" etc. H becomes the starting line
number and the other variables that should increment but don't. I am
modifying older code that works but is not as efficient that does not use the
loop routine.

Any help is much appreciated.

Private Sub cmdOK_Click()
Dim H As Integer, lineno As Integer, newno As Integer

ActiveCell.Activate
ActiveCell.FormulaR1C1 = TextBox1.Value
ActiveCell.Offset(RowOffset:=1, ColumnOffset:=0).Activate
Selection.ClearContents
H = TextBox1.Value 'from textbox1 on userform1
Do Until lineno = TextBox2.Value 'value in textbox2 on userform1
lineno = H
ActiveCell.Offset(RowOffset:=4, ColumnOffset:=0).Activate
ActiveCell.FormulaR1C1 = H + newno
newno = 1
ActiveCell.Offset(RowOffset:=1, ColumnOffset:=0).Activate
Selection.ClearContents
newno = H + newno
Loop
Exit Sub


End Sub