View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
N E Body N E Body is offline
external usenet poster
 
Posts: 34
Default Spinbutton help required

For some reason the code you gave me returned a number two less than what
was entered.

The number I entered is an ID number in column A

I presume Excel sees this numberin the TextBox as a Row number as my ID
number (x) is in Row (x-2)

Oddly enough I answered my own question in my last thread - when I added +2
to your code it returned the value I expected.

Many thanks again

Kenny
and yes N E Body is Kennyatwork, Kennyathome etc of www.crathornehall.com
fame (you have assisted me many times!!!)

"Bob Phillips" wrote in message
...
Don't understand what you are saying.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"N E Body" wrote in message
...
Thanks Bob

If I type in 40 then click spinup it returns 38??
This is because it is refering to row numbers and 38 is row 41 columnA
value! (it is working because it has advanced one row!)

Is it possible to advance 2 rows down

something like
SpinButton1.Value = TextBox1.Text+2

TIA

Kenny


"Bob Phillips" wrote in message
...
Just add this

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

SpinButton1.Value = TextBox1.Text
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"N E Body" wrote in message
...
Many thanks Tom

I have got it working on my userform apart from 1 problem which I

cannot
fix.

If I enter a number into TextBox2 then click spinup/down I would

like
the
number in textbox2 to advance/decrease by one.
With my code TextBox2 is populated with a low number then spins from

that
number!

How do I correct this?

Sample of my code below

Many thanks

Kenny

Private Sub UserForm_initialize()

SpinButton1.Max = 3000
SpinButton1.Min = 4
SpinButton1.Value = 4

End Sub



Private Sub SpinButton1_SpinUp()

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

ans = LogEntry.TextBox2.Value
res = Application.Match(CLng(ans), Range("A4:A3000"), 0)
Range("A4:A3000")(res).Activate

IdentRetrieve1

End Sub



Private Sub SpinButton1_SpinDown()

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

ans = LogEntry.TextBox2.Value
res = Application.Match(CLng(ans), Range("A4:A3000"), 0)
Range("A4:A3000")(res).Activate

IdentRetrieve1

End Sub






"Tom Ogilvy" wrote in message
...
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