View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Spinbutton help required

There is no trick to it.

Use the spinup and spindown events to increment an index into your range and
retrieve the value. Assign the retrieved value to the textbox. Set the
min and max values so the spinbutton will not go outside your range.

Private Sub SpinButton1_SpinUp()
idex = SpinButton1.Value
With Worksheets(1)
TextBox2.Text = .Range("A1")(idex)
End With
End Sub
Private Sub SpinButton1_SpinDown()
idex = SpinButton1.Value
With Worksheets(1)
TextBox2.Text = .Range("A1")(idex)
End With
End Sub


Private Sub UserForm_Initialize()
SpinButton1.Max = 20
SpinButton1.Min = 1
SpinButton1.Value = 10
End Sub


The buttons in this case work opposite of the rows (spindown increases the
row addressed). However, with increasing values in the cell, it works OK
depending on your perspective. However, if you want to have spinup decrease
the row (arrow points in the direction of row change), you can use

Private Sub SpinButton1_SpinUp()
idex = 21 - SpinButton1.Value
With Worksheets(1)
TextBox2.Text = .Range("A1")(idex)
End With
End Sub

as an example (similar change in SpinDown).


--
Regards,
Tom Ogilvy

"N E Body" wrote in message
...
Hello everyone

Can anyone direct me to a site where I can learn how to code a spin

button?
I have not used one before and I have not got a clue where to start!

I want to use it in the following manner,

I have an Excel database that has a userform for entering and retreiving
data. The form has several fields - one of which is TextBox2 which shows
the entry number.
I would like to add a spinner to TextBox2 so I can select the previous or
next entry and show the details in the other fields.

I would be glad of any advice!

Kenny

Win 2000 and Millennium
Excel 97 and 2000