Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Deleting value in TextBox with SpinButton attached

I have a UserForm with a series of TextBoxes each with a SpinButton
attached. The user can either enter a value into the TextBox or use
the SpinButton to change the value. This value is then returned to a
cell for calculations to be made. If the user selects the value in the
TextBox and presses delete, the value changes to a zero. If the zero
is deleted, only then is the TextBox cleared. I would like the TextBox
to be cleared the first time delete is pressed as the user might not
notice the value has changed to zero. I have also tried to clear the
value using code to set the ControlSource cell value to "" but this
leaves zeroes as well.

Any help would be very much appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Deleting value in TextBox with SpinButton attached

set rng = Range(Textbox1.ControlSource)
rng.clearContents
Textbox1.Value = ""

--
Regards,
Tom Ogilvy



"markb" wrote:

I have a UserForm with a series of TextBoxes each with a SpinButton
attached. The user can either enter a value into the TextBox or use
the SpinButton to change the value. This value is then returned to a
cell for calculations to be made. If the user selects the value in the
TextBox and presses delete, the value changes to a zero. If the zero
is deleted, only then is the TextBox cleared. I would like the TextBox
to be cleared the first time delete is pressed as the user might not
notice the value has changed to zero. I have also tried to clear the
value using code to set the ControlSource cell value to "" but this
leaves zeroes as well.

Any help would be very much appreciated.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Deleting value in TextBox with SpinButton attached

Tom
Many thanks for your reply. Please forgive my ignorance, but I'm not
sure where to include this code.

On 27 Feb, 14:35, Tom Ogilvy
wrote:
set rng = Range(Textbox1.ControlSource)
rng.clearContents
Textbox1.Value = ""

--
Regards,
Tom Ogilvy



"markb" wrote:
I have a UserForm with a series of TextBoxes each with a SpinButton
attached. The user can either enter a value into the TextBox or use
the SpinButton to change the value. This value is then returned to a
cell for calculations to be made. If the user selects the value in the
TextBox and presses delete, the value changes to a zero. If the zero
is deleted, only then is the TextBox cleared. I would like the TextBox
to be cleared the first time delete is pressed as the user might not
notice the value has changed to zero. I have also tried to clear the
value using code to set the ControlSource cell value to "" but this
leaves zeroes as well.


Any help would be very much appreciated.- Hide quoted text -


- Show quoted text -



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Deleting value in TextBox with SpinButton attached

I can't say for sure. I don't have the big picture on what you are doing or
what happens when or what values are acceptable in the textbox. My first
guess would be the change event of the textbox. Have an if statement check
if the textbox is blank or has a 0 in it. If so, run the code. Or use the
exit event.

--
Regards,
Tom Ogilvy


"markb" wrote:

Tom
Many thanks for your reply. Please forgive my ignorance, but I'm not
sure where to include this code.

On 27 Feb, 14:35, Tom Ogilvy
wrote:
set rng = Range(Textbox1.ControlSource)
rng.clearContents
Textbox1.Value = ""

--
Regards,
Tom Ogilvy



"markb" wrote:
I have a UserForm with a series of TextBoxes each with a SpinButton
attached. The user can either enter a value into the TextBox or use
the SpinButton to change the value. This value is then returned to a
cell for calculations to be made. If the user selects the value in the
TextBox and presses delete, the value changes to a zero. If the zero
is deleted, only then is the TextBox cleared. I would like the TextBox
to be cleared the first time delete is pressed as the user might not
notice the value has changed to zero. I have also tried to clear the
value using code to set the ControlSource cell value to "" but this
leaves zeroes as well.


Any help would be very much appreciated.- Hide quoted text -


- Show quoted text -




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Deleting value in TextBox with SpinButton attached

Thanks again for your help, Tom. I'll try your suggestions.

On Feb 27, 7:21 pm, Tom Ogilvy
wrote:
I can't say for sure. I don't have the big picture on what you are doing or
what happens when or what values are acceptable in the textbox. My first
guess would be the change event of the textbox. Have an if statement check
if the textbox is blank or has a 0 in it. If so, run the code. Or use the
exit event.

--
Regards,
Tom Ogilvy



"markb" wrote:
Tom
Many thanks for your reply. Please forgive my ignorance, but I'm not
sure where to include this code.


On 27 Feb, 14:35, Tom Ogilvy
wrote:
set rng = Range(Textbox1.ControlSource)
rng.clearContents
Textbox1.Value = ""


--
Regards,
Tom Ogilvy


"markb" wrote:
I have a UserForm with a series of TextBoxes each with a SpinButton
attached. The user can either enter a value into the TextBox or use
the SpinButton to change the value. This value is then returned to a
cell for calculations to be made. If the user selects the value in the
TextBox and presses delete, the value changes to a zero. If the zero
is deleted, only then is the TextBox cleared. I would like the TextBox
to be cleared the first time delete is pressed as the user might not
notice the value has changed to zero. I have also tried to clear the
value using code to set the ControlSource cell value to "" but this
leaves zeroes as well.


Any help would be very much appreciated.- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Deleting value in TextBox with SpinButton attached

I have tried to use the code you suggested in the following ways:
Firstly I have a procedu

Sub clearTextBox1()
Set rng = Range(TextBox1.ControlSource)
rng.ClearContents
TextBox1.Value = ""
End Sub

I have then used:

Application.OnKey "{DELETE}","clearTextBox1"

In both a Change event or KeyPress event for TextBox1

I have also tried an Exit event:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value = "" Then clearTextBox1
End Sub

In every case if the user deletes a value in TextBox1, the value
appears to clear until Enter or Tab is pressed at which point a zero
re-appears in TextBox1. If the zero is deleted, then the TextBox
remains clear.

These TextBoxes are used for percentages so the permitted values are
0-100. But I also need a blank to be permitted. The Excel calculations
based on the output of this TextBox will treat a zero value and a
blank differently. Specifically, a zero will indicate a 0% occupancy
for a hotel room, but a blank will force the calculation to use an
average occupancy rate from a different cell.


On Feb 27, 7:21 pm, Tom Ogilvy
wrote:
I can't say for sure. I don't have the big picture on what you are doing or
what happens when or what values are acceptable in the textbox. My first
guess would be the change event of the textbox. Have an if statement check
if the textbox is blank or has a 0 in it. If so, run the code. Or use the
exit event.

--
Regards,
Tom Ogilvy



"markb" wrote:
Tom
Many thanks for your reply. Please forgive my ignorance, but I'm not
sure where to include this code.


On 27 Feb, 14:35, Tom Ogilvy
wrote:
set rng = Range(Textbox1.ControlSource)
rng.clearContents
Textbox1.Value = ""


--
Regards,
Tom Ogilvy


"markb" wrote:
I have a UserForm with a series of TextBoxes each with a SpinButton
attached. The user can either enter a value into the TextBox or use
the SpinButton to change the value. This value is then returned to a
cell for calculations to be made. If the user selects the value in the
TextBox and presses delete, the value changes to a zero. If the zero
is deleted, only then is the TextBox cleared. I would like the TextBox
to be cleared the first time delete is pressed as the user might not
notice the value has changed to zero. I have also tried to clear the
value using code to set the ControlSource cell value to "" but this
leaves zeroes as well.


Any help would be very much appreciated.- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting value in TextBox with SpinButton attached

I would break the link between the textbox and the cell (remove the
controlsource if this is a userform or the linkedcell property if on a
worksheet). Then use the change event to update the cell.

without the link, there is nothing that should change the value of the
textbox. This assumes you don't manually make changes in the cell and want
them reflected in the textbox and don't have any code that does that.

--
Regards,
Tom Ogilvy


"markb" wrote in message
oups.com...
I have tried to use the code you suggested in the following ways:
Firstly I have a procedu

Sub clearTextBox1()
Set rng = Range(TextBox1.ControlSource)
rng.ClearContents
TextBox1.Value = ""
End Sub

I have then used:

Application.OnKey "{DELETE}","clearTextBox1"

In both a Change event or KeyPress event for TextBox1

I have also tried an Exit event:

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value = "" Then clearTextBox1
End Sub

In every case if the user deletes a value in TextBox1, the value
appears to clear until Enter or Tab is pressed at which point a zero
re-appears in TextBox1. If the zero is deleted, then the TextBox
remains clear.

These TextBoxes are used for percentages so the permitted values are
0-100. But I also need a blank to be permitted. The Excel calculations
based on the output of this TextBox will treat a zero value and a
blank differently. Specifically, a zero will indicate a 0% occupancy
for a hotel room, but a blank will force the calculation to use an
average occupancy rate from a different cell.


On Feb 27, 7:21 pm, Tom Ogilvy
wrote:
I can't say for sure. I don't have the big picture on what you are doing
or
what happens when or what values are acceptable in the textbox. My
first
guess would be the change event of the textbox. Have an if statement
check
if the textbox is blank or has a 0 in it. If so, run the code. Or use
the
exit event.

--
Regards,
Tom Ogilvy



"markb" wrote:
Tom
Many thanks for your reply. Please forgive my ignorance, but I'm not
sure where to include this code.


On 27 Feb, 14:35, Tom Ogilvy
wrote:
set rng = Range(Textbox1.ControlSource)
rng.clearContents
Textbox1.Value = ""


--
Regards,
Tom Ogilvy


"markb" wrote:
I have a UserForm with a series of TextBoxes each with a SpinButton
attached. The user can either enter a value into the TextBox or use
the SpinButton to change the value. This value is then returned to
a
cell for calculations to be made. If the user selects the value in
the
TextBox and presses delete, the value changes to a zero. If the
zero
is deleted, only then is the TextBox cleared. I would like the
TextBox
to be cleared the first time delete is pressed as the user might
not
notice the value has changed to zero. I have also tried to clear
the
value using code to set the ControlSource cell value to "" but this
leaves zeroes as well.


Any help would be very much appreciated.- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Deleting value in TextBox with SpinButton attached

Unfortunately this creates other problems because of the link between
the TextBox and SpinButton. I'm now thinking that it is this link that
is causing the problem.

The SpinButton has a permitted value between 0 and 100. If the user
changes the TextBox, this updates the SpinButton and vice versa. So if
a user deletes the value in the TextBox, maybe the SpinButton can only
read this as a zero and so returns zero back to the TextBox?? As zero
is a permitted value sometimes, I can't use an If statement to replace
a zero with a blank.

Worst case, I could change my calculations so a blank and zero are
treated the same way, and then get the conditionality I wanted some
other way, like a CheckBox. But there are 36000 formulae in my
worksheet, so any other ideas would be very welcome!

Regards
markb



On Mar 2, 1:46 am, "Tom Ogilvy" wrote:
I would break the link between the textbox and the cell (remove the
controlsource if this is a userform or the linkedcell property if on a
worksheet). Then use the change event to update the cell.

without the link, there is nothing that should change the value of the
textbox. This assumes you don't manually make changes in the cell and want
them reflected in the textbox and don't have any code that does that.

--
Regards,
Tom Ogilvy

"markb" wrote in message

oups.com...



I have tried to use the code you suggested in the following ways:
Firstly I have a procedu


Sub clearTextBox1()
Set rng = Range(TextBox1.ControlSource)
rng.ClearContents
TextBox1.Value = ""
End Sub


I have then used:


Application.OnKey "{DELETE}","clearTextBox1"


In both a Change event or KeyPress event for TextBox1


I have also tried an Exit event:


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value = "" Then clearTextBox1
End Sub


In every case if the user deletes a value in TextBox1, the value
appears to clear until Enter or Tab is pressed at which point a zero
re-appears in TextBox1. If the zero is deleted, then the TextBox
remains clear.


These TextBoxes are used for percentages so the permitted values are
0-100. But I also need a blank to be permitted. The Excel calculations
based on the output of this TextBox will treat a zero value and a
blank differently. Specifically, a zero will indicate a 0% occupancy
for a hotel room, but a blank will force the calculation to use an
average occupancy rate from a different cell.


On Feb 27, 7:21 pm, Tom Ogilvy
wrote:
I can't say for sure. I don't have the big picture on what you are doing
or
what happens when or what values are acceptable in the textbox. My
first
guess would be the change event of the textbox. Have an if statement
check
if the textbox is blank or has a 0 in it. If so, run the code. Or use
the
exit event.


--
Regards,
Tom Ogilvy


"markb" wrote:
Tom
Many thanks for your reply. Please forgive my ignorance, but I'm not
sure where to include this code.


On 27 Feb, 14:35, Tom Ogilvy
wrote:
set rng = Range(Textbox1.ControlSource)
rng.clearContents
Textbox1.Value = ""


--
Regards,
Tom Ogilvy


"markb" wrote:
I have a UserForm with a series of TextBoxes each with a SpinButton
attached. The user can either enter a value into the TextBox or use
the SpinButton to change the value. This value is then returned to
a
cell for calculations to be made. If the user selects the value in
the
TextBox and presses delete, the value changes to a zero. If the
zero
is deleted, only then is the TextBox cleared. I would like the
TextBox
to be cleared the first time delete is pressed as the user might
not
notice the value has changed to zero. I have also tried to clear
the
value using code to set the ControlSource cell value to "" but this
leaves zeroes as well.


Any help would be very much appreciated.- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting value in TextBox with SpinButton attached

I don't know how you have a spinbutton linked to your textbox.



--
Regards,
Tom Ogilvy


"markb" wrote in message
ups.com...
Unfortunately this creates other problems because of the link between
the TextBox and SpinButton. I'm now thinking that it is this link that
is causing the problem.

The SpinButton has a permitted value between 0 and 100. If the user
changes the TextBox, this updates the SpinButton and vice versa. So if
a user deletes the value in the TextBox, maybe the SpinButton can only
read this as a zero and so returns zero back to the TextBox?? As zero
is a permitted value sometimes, I can't use an If statement to replace
a zero with a blank.

Worst case, I could change my calculations so a blank and zero are
treated the same way, and then get the conditionality I wanted some
other way, like a CheckBox. But there are 36000 formulae in my
worksheet, so any other ideas would be very welcome!

Regards
markb



On Mar 2, 1:46 am, "Tom Ogilvy" wrote:
I would break the link between the textbox and the cell (remove the
controlsource if this is a userform or the linkedcell property if on a
worksheet). Then use the change event to update the cell.

without the link, there is nothing that should change the value of the
textbox. This assumes you don't manually make changes in the cell and
want
them reflected in the textbox and don't have any code that does that.

--
Regards,
Tom Ogilvy

"markb" wrote in message

oups.com...



I have tried to use the code you suggested in the following ways:
Firstly I have a procedu


Sub clearTextBox1()
Set rng = Range(TextBox1.ControlSource)
rng.ClearContents
TextBox1.Value = ""
End Sub


I have then used:


Application.OnKey "{DELETE}","clearTextBox1"


In both a Change event or KeyPress event for TextBox1


I have also tried an Exit event:


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1.Value = "" Then clearTextBox1
End Sub


In every case if the user deletes a value in TextBox1, the value
appears to clear until Enter or Tab is pressed at which point a zero
re-appears in TextBox1. If the zero is deleted, then the TextBox
remains clear.


These TextBoxes are used for percentages so the permitted values are
0-100. But I also need a blank to be permitted. The Excel calculations
based on the output of this TextBox will treat a zero value and a
blank differently. Specifically, a zero will indicate a 0% occupancy
for a hotel room, but a blank will force the calculation to use an
average occupancy rate from a different cell.


On Feb 27, 7:21 pm, Tom Ogilvy
wrote:
I can't say for sure. I don't have the big picture on what you are
doing
or
what happens when or what values are acceptable in the textbox. My
first
guess would be the change event of the textbox. Have an if statement
check
if the textbox is blank or has a 0 in it. If so, run the code. Or
use
the
exit event.


--
Regards,
Tom Ogilvy


"markb" wrote:
Tom
Many thanks for your reply. Please forgive my ignorance, but I'm not
sure where to include this code.


On 27 Feb, 14:35, Tom Ogilvy
wrote:
set rng = Range(Textbox1.ControlSource)
rng.clearContents
Textbox1.Value = ""


--
Regards,
Tom Ogilvy


"markb" wrote:
I have a UserForm with a series of TextBoxes each with a
SpinButton
attached. The user can either enter a value into the TextBox or
use
the SpinButton to change the value. This value is then returned
to
a
cell for calculations to be made. If the user selects the value
in
the
TextBox and presses delete, the value changes to a zero. If the
zero
is deleted, only then is the TextBox cleared. I would like the
TextBox
to be cleared the first time delete is pressed as the user might
not
notice the value has changed to zero. I have also tried to clear
the
value using code to set the ControlSource cell value to "" but
this
leaves zeroes as well.


Any help would be very much appreciated.- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spinbutton Mysteriously Erases Textbox [email protected] Excel Programming 3 February 12th 07 03:23 AM
SpinButton/TextBox - Large Number John Fuller Excel Programming 3 September 21st 06 03:19 PM
TextBox Attached to AutoShape Phil H[_2_] Excel Programming 3 March 27th 06 07:49 AM
Deleting a textbox control at runtime Grant Williams Excel Programming 3 June 14th 04 08:33 AM
Spinbutton Linked to Textbox David Reid[_2_] Excel Programming 2 August 19th 03 04:25 PM


All times are GMT +1. The time now is 10:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"