Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Very basic VBA questions.

How do you get a VBA code to reference the value of a cell in a worksheet and
use it in an equation? An example of what I'm trying to do is; If you click
on "Spring" I want B27=L175. If you click on "Spring w/Liftable" the
equation would then be B27=L175-K195.

Also, Is there a way to have a text box in a user form to read a cell? So
basically I would like the text box to have the same value as what is in K196.

Thanks for any help on this in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Very basic VBA questions.

Not too sure what you mena by click on spring but generally speaking your
code will look something like this...

Sheets("sheet1").range("B27").formula = "=L175"
or
Sheets("sheet1").range("B27").formula = "=L175-k195"

As for the text box a user form will have an initalize event so something
like this...

Private Sub UserForm_Initialize()
TextBox1.Text = Sheets("Sheet1").Range("K196").Value
End Sub
--
HTH...

Jim Thomlinson


"Cerberus" wrote:

How do you get a VBA code to reference the value of a cell in a worksheet and
use it in an equation? An example of what I'm trying to do is; If you click
on "Spring" I want B27=L175. If you click on "Spring w/Liftable" the
equation would then be B27=L175-K195.

Also, Is there a way to have a text box in a user form to read a cell? So
basically I would like the text box to have the same value as what is in K196.

Thanks for any help on this in advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Very basic VBA questions.

Thank you for your help and sorry abot the multiple posts

"Jim Thomlinson" wrote:

Not too sure what you mena by click on spring but generally speaking your
code will look something like this...

Sheets("sheet1").range("B27").formula = "=L175"
or
Sheets("sheet1").range("B27").formula = "=L175-k195"

As for the text box a user form will have an initalize event so something
like this...

Private Sub UserForm_Initialize()
TextBox1.Text = Sheets("Sheet1").Range("K196").Value
End Sub
--
HTH...

Jim Thomlinson


"Cerberus" wrote:

How do you get a VBA code to reference the value of a cell in a worksheet and
use it in an equation? An example of what I'm trying to do is; If you click
on "Spring" I want B27=L175. If you click on "Spring w/Liftable" the
equation would then be B27=L175-K195.

Also, Is there a way to have a text box in a user form to read a cell? So
basically I would like the text box to have the same value as what is in K196.

Thanks for any help on this in advance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Very basic VBA questions.

Sorry to bother but on making the Text box read the same as a cell, I put

Private Sub TextAxLeft_Initialize()
TextAxLeft.Text = Range("K198").Value
End Sub

in and the text box is blank. I assumed that since the sheet is active, I
could leave off the sheet reference. Was I wrong in assuming that or did I
do something else wrong? Thanks again.

P.S. Thanks again for the info on using the cells in a formula.

"Jim Thomlinson" wrote:

Not too sure what you mena by click on spring but generally speaking your
code will look something like this...

Sheets("sheet1").range("B27").formula = "=L175"
or
Sheets("sheet1").range("B27").formula = "=L175-k195"

As for the text box a user form will have an initalize event so something
like this...

Private Sub UserForm_Initialize()
TextBox1.Text = Sheets("Sheet1").Range("K196").Value
End Sub
--
HTH...

Jim Thomlinson


"Cerberus" wrote:

How do you get a VBA code to reference the value of a cell in a worksheet and
use it in an equation? An example of what I'm trying to do is; If you click
on "Spring" I want B27=L175. If you click on "Spring w/Liftable" the
equation would then be B27=L175-K195.

Also, Is there a way to have a text box in a user form to read a cell? So
basically I would like the text box to have the same value as what is in K196.

Thanks for any help on this in advance.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Very basic VBA questions.

My assumption in answering your question is that you have added a userform to
your spreadsheet. By that I mean you went into the VBE and inserted a
userform. You then added a text box to that userform. Let me know if that
assumption is incorrect.

Assuming it is correct then a userform has a number of events that it
tracks. Just above the code window on the left is a drop down of all of the
objects associate with the parent object you are in (the userform in this
case). Select userform from that drop down. That will add an on click event
procedure to your project. On the right is a drop down of all of the events.
Select initialize. That adds a inititialize event procedure to your project.
You can not change the names of these procedures. That is where you have run
into a problem. You changed
Private Sub UserForm_Initialize()
to
Private Sub TextAxLeft_Initialize()

which will not work.
--
HTH...

Jim Thomlinson


"Cerberus" wrote:

Sorry to bother but on making the Text box read the same as a cell, I put

Private Sub TextAxLeft_Initialize()
TextAxLeft.Text = Range("K198").Value
End Sub

in and the text box is blank. I assumed that since the sheet is active, I
could leave off the sheet reference. Was I wrong in assuming that or did I
do something else wrong? Thanks again.

P.S. Thanks again for the info on using the cells in a formula.

"Jim Thomlinson" wrote:

Not too sure what you mena by click on spring but generally speaking your
code will look something like this...

Sheets("sheet1").range("B27").formula = "=L175"
or
Sheets("sheet1").range("B27").formula = "=L175-k195"

As for the text box a user form will have an initalize event so something
like this...

Private Sub UserForm_Initialize()
TextBox1.Text = Sheets("Sheet1").Range("K196").Value
End Sub
--
HTH...

Jim Thomlinson


"Cerberus" wrote:

How do you get a VBA code to reference the value of a cell in a worksheet and
use it in an equation? An example of what I'm trying to do is; If you click
on "Spring" I want B27=L175. If you click on "Spring w/Liftable" the
equation would then be B27=L175-K195.

Also, Is there a way to have a text box in a user form to read a cell? So
basically I would like the text box to have the same value as what is in K196.

Thanks for any help on this in advance.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Very basic VBA questions.

It worked, Thanks Jim.

"Jim Thomlinson" wrote:

My assumption in answering your question is that you have added a userform to
your spreadsheet. By that I mean you went into the VBE and inserted a
userform. You then added a text box to that userform. Let me know if that
assumption is incorrect.

Assuming it is correct then a userform has a number of events that it
tracks. Just above the code window on the left is a drop down of all of the
objects associate with the parent object you are in (the userform in this
case). Select userform from that drop down. That will add an on click event
procedure to your project. On the right is a drop down of all of the events.
Select initialize. That adds a inititialize event procedure to your project.
You can not change the names of these procedures. That is where you have run
into a problem. You changed
Private Sub UserForm_Initialize()
to
Private Sub TextAxLeft_Initialize()

which will not work.
--
HTH...

Jim Thomlinson


"Cerberus" wrote:

Sorry to bother but on making the Text box read the same as a cell, I put

Private Sub TextAxLeft_Initialize()
TextAxLeft.Text = Range("K198").Value
End Sub

in and the text box is blank. I assumed that since the sheet is active, I
could leave off the sheet reference. Was I wrong in assuming that or did I
do something else wrong? Thanks again.

P.S. Thanks again for the info on using the cells in a formula.

"Jim Thomlinson" wrote:

Not too sure what you mena by click on spring but generally speaking your
code will look something like this...

Sheets("sheet1").range("B27").formula = "=L175"
or
Sheets("sheet1").range("B27").formula = "=L175-k195"

As for the text box a user form will have an initalize event so something
like this...

Private Sub UserForm_Initialize()
TextBox1.Text = Sheets("Sheet1").Range("K196").Value
End Sub
--
HTH...

Jim Thomlinson


"Cerberus" wrote:

How do you get a VBA code to reference the value of a cell in a worksheet and
use it in an equation? An example of what I'm trying to do is; If you click
on "Spring" I want B27=L175. If you click on "Spring w/Liftable" the
equation would then be B27=L175-K195.

Also, Is there a way to have a text box in a user form to read a cell? So
basically I would like the text box to have the same value as what is in K196.

Thanks for any help on this in advance.

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
Basic Questions Peter Excel Programming 5 July 1st 07 07:32 PM
Basic questions Maine begins Excel Discussion (Misc queries) 1 July 7th 06 06:45 PM
Basic Pivot Table Questions shadestreet Excel Discussion (Misc queries) 0 April 17th 06 04:58 PM
2 basic Excel questions for you pro's cjtj4700 Excel Discussion (Misc queries) 7 November 24th 05 07:31 PM
EXCEL Visual Basic Questions Dean[_8_] Excel Programming 3 May 9th 05 09:03 PM


All times are GMT +1. The time now is 10:01 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"