Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placing an answer in a textbox

Status
Not open for further replies.

metal24

Technical User
Oct 9, 2008
1
ZA
Please help. I am trying to calculate a formula then let the textbox show the number. The textbox's controlsource is d23. The formula should be in cell d23. I want to subtract d22-d21, which is control sources of two other textboxes. Can someone have a look at my two codes below, and tell me what I am doing wrong, if you need the excel file let me know.

Private Sub txtironmass_Change()
Dim myrange1 As range

Set myrange1 = Worksheets("program").range("d23")
If Cells("d22") > 0 Then

myrange1("D23").Select
ActiveCell.FormulaR1C1 = "=R[-1]C-R[-2]C"
Else: range("d23").Select = 0

End If
End Sub


Private Sub txtironmass_Change()
Dim x As range
Set x = Worksheets("program").range("d23")
x.Select
ActiveCell.Formula = "=z-y"

End Sub
 




Hi,

I do not understand what you are trying to do.

Here are your procedures cleaned up to make a bit more sense. 1) you cannot have procedures with the same name. 2) why would you call either a textbox change procedure? 3) how are y & z defined on your sheet?
Code:
Private Sub Proc1()
    Dim myrange1 As Range
    
    Set myrange1 = Worksheets("program").Range("d23")
    If Range("d22") > 0 Then
       myrange1.FormulaR1C1 = "=R[-1]C-R[-2]C"
    Else
        myrange1.Value = 0
    End If
    
    txtironmass.Text = myrange1.Value
End Sub

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top