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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

having a result go to a textbox 1

Status
Not open for further replies.

Claulle

Technical User
May 22, 2003
37
DK
Greetings

Please forgive me, but i realy seldom use Execel so im a real novice :)

Lets say i have 2 cells; A1 = 20 and A2 = 30. I also have a Textbox wich i need to have the text: "The sum is:" + the value of A1+A2.

Can anyone tell me how to do that?

I think i have read all the posts regarding this but unfortunatly they have not helped me.

Kindly regard
Claus
 
sub display_result()

msgbox("The sum is: " + cstr(range("A1")+range("A2")))

end sub
 
Where exactly should i insert that code ?

Like i said, im new to this :)

/Claus
 
right click on the sheet name tab....choose view code
then, in the right frame choose the "(general)" drop down, choose worksheet, then in the "(declarations)" choose a user action event that will luanch this code.

excel will generate a "sub" for you
paste this line only....between the sub_name()
and end sub

msgbox("The sum is: " + cstr(range("A1")+range("A2")))


alt+f11 to return to the worksheet.



 
Nice! I see how that works!

Lets say i want a textbox. the ideal was to make a textbox under the drawing tools, and have the result go in there. Can that be done ?

/Claus
 
ActiveSheet.Shapes("Text Box 1").Select

Selection.Characters.Text = "The sum is: " + cstr(range("A1")+range("A2"))

SendKeys (Chr$(27))

'NOTE: "Text Box 1" is a generic name, you can find the name of yours by highliting the box for edit, and looking at the "name box" above cell A1
 
...Just an FYI, if you turn on the macro recorder,..step through the actions that you want to perform, then turn off the recorder.

then alt+f11 to view the code that excel has auto generated.

...you can usually see enough to get a grasp of where to splice in variables to make your code more custom to a specific situation.

...also explore the vba editor, right clicking in the code area of a sub will most often give you a properties or methods list to choose from if you get stuck.

but it can be criptic until you gain some experience.
 
That works! Have a star and many thanks for your willing to help :)

Guess i need to read a few Visual Basic books :)

Thanks again!

Kind regards
Claus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top