Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default How calculate a difference btwn 2 TextBox and insert the result inthe appropriate cell

Hello to eveybody,
How may I calculate a difference btwn [TextBox2]-[TextBox3] in a
UserForm, show the result in [TextBox5] and insert the result in the
appropriate cell D of the PaperReceipt worksheet when I click on a button?

The [TextBox3] initially has the same value has [TextBox2] but in the
TextBox I need sometime to change the number.
Thanks in advance.
Regards
John


In the UserForm there is a combo and the code behind is:

Private Sub mSearch(ByVal vValore As Variant)
Dim rng As Range
With sh
'search value column D
Set rng = _
.Range("D:D").Find( _
What:=vValore, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlRows, _
SearchDirection:=xlNext, _
MatchCase:=True)
End With
'chek result
If rng Is Nothing Then
'if no
MsgBox "Data nof found"
'clean TextBox
Call mClear TextBox
Else
Me.TextBox2.Text = rng.Offset(0, 3).Value
Me.TextBox3.Text = rng.Offset(0, 3).Value
Me.TextBox4.Text = rng.Offset(0, 2).Value
End If
Set rng = Nothing
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 420
Default How calculate a difference btwn 2 TextBox and insert the resultin the appropriate cell

Since you're using textboxes, I think you'd be wise to check to see if the
values are numeric:

if isnumeric(me.textbox2.value) _
and isnumeric(me.textbox3.value) then
me.textbox5.value = me.textbox2.value - me.textbox3.value
else
me.textbox5.value = "Please enter numbers!"
end if

You may want to even format that result:
me.textbox5.value = format(me.textbox2.value - me.textbox3.value, "0.00")

(untested and uncompiled -- watch for typos)


On 11/19/2011 01:34, John wrote:
Hello to eveybody,
How may I calculate a difference btwn [TextBox2]-[TextBox3] in a UserForm, show
the result in [TextBox5] and insert the result in the appropriate cell D of the
PaperReceipt worksheet when I click on a button?

The [TextBox3] initially has the same value has [TextBox2] but in the TextBox I
need sometime to change the number.
Thanks in advance.
Regards
John


In the UserForm there is a combo and the code behind is:

Private Sub mSearch(ByVal vValore As Variant)
Dim rng As Range
With sh
'search value column D
Set rng = _
.Range("D:D").Find( _
What:=vValore, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlRows, _
SearchDirection:=xlNext, _
MatchCase:=True)
End With
'chek result
If rng Is Nothing Then
'if no
MsgBox "Data nof found"
'clean TextBox
Call mClear TextBox
Else
Me.TextBox2.Text = rng.Offset(0, 3).Value
Me.TextBox3.Text = rng.Offset(0, 3).Value
Me.TextBox4.Text = rng.Offset(0, 2).Value
End If
Set rng = Nothing
End Sub


--
Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default How calculate a difference btwn 2 TextBox and insert the resultin the appropriate cell

Il 19/11/2011 13:50, Dave Peterson ha scritto:
me.textbox5.value = format(me.textbox2.value - me.textbox3.value, "0.00")

Thanks Dave,
it is OK.
One more question if you allowed me:
how may update the source (the cell in column D) in the worksheet with
the Me.TextBox5.value?

Thanks and Regards
John
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 420
Default How calculate a difference btwn 2 TextBox and insert the resultin the appropriate cell

rng.value = me.textbox5.value

or maybe:
with rng
.numberformat = "0.00"
.value = me.textbox5.value
end with



On 11/19/2011 10:43, John wrote:
Il 19/11/2011 13:50, Dave Peterson ha scritto:
me.textbox5.value = format(me.textbox2.value - me.textbox3.value, "0.00")

Thanks Dave,
it is OK.
One more question if you allowed me:
how may update the source (the cell in column D) in the worksheet with the
Me.TextBox5.value?

Thanks and Regards
John


--
Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default How calculate a difference btwn 2 TextBox and insert the resultin the appropriate cell


Thanks for all your support. Solved.
Regards
John
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
Time difference btwn entries Kashyap Excel Worksheet Functions 1 April 27th 09 06:15 PM
Calculate Textbox value based on another textbox value.doc Tdungate Excel Discussion (Misc queries) 1 February 12th 09 07:11 PM
Calculate Textbox value based on another textbox value Tdungate Excel Discussion (Misc queries) 0 February 12th 09 07:03 PM
CALCULATE DIFFERENCE BETWEEN 2 TIMES - RESULT IN MINUTES CB Excel Discussion (Misc queries) 3 May 21st 07 09:59 PM
formatt to Calculate difference in now() and date in cell, GARDNERGUY Excel Discussion (Misc queries) 1 April 27th 07 04:06 AM


All times are GMT +1. The time now is 01:09 PM.

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

About Us

"It's about Microsoft Excel"