Sending Textbox values to specific cells

blakesmith

New Member
Joined
May 26, 2011
Messages
4
I have created a 9 text boxes in a userform as well as a command button. I want to be able to enter simple information in the text boxes and have excel send that info to desired cells.

For instance; first name ________ (to C9); last name _________ (to C10); address_________ (to C11) etc...

What is the code to send a specific textbox to a specific cell? Also how could I send the same info to more than one cell?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
For instance; first name ________ (to C9); last name _________ (to C10); address_________ (to C11) etc...

What is the code to send a specific textbox to a specific cell?

There are a few options depending on what event you want to have trigger copying the textbox value to the cells.

If you want that to happen when your command button is clicked...

Code:
Private Sub OK_Click()
    Sheets("Sheet1").Range("C9") = TextBox1.value
    Sheets("Sheet1").Range("C10") = TextBox2.value
End Sub

You could instead copy the value as soon as it is changed in the textbox as shown below....however this doesn't work as well if you want to allow the user to cancel out of the userform without executing the changes.

Code:
Private Sub TextBox1_Change()
    Sheets("Sheet1").Range("C9") = TextBox1.value
End Sub
 
Private Sub TextBox2_Change()
    Sheets("Sheet1").Range("C10") = TextBox2.value
End Sub

Also how could I send the same info to more than one cell?

You can copy the same value to more than cell with by adding the cells to the range reference, or adding additional statements.

Code:
Private Sub OK_Click()
    Sheets("Sheet1").Range("C9,D9,E2") = TextBox1.value
    Sheets("Sheet12).Range("C9") = TextBox1.value
End Sub

As an alternative, you might consider copying the value to just one cell in your worksheet, and having the other cells reference that cell with a formula if your intent is for them to always be the same.
 
Upvote 0
A little trickier question....

I am now looking to send some of the textbox values to a different workbook and I need a macro to find the next empty cell and put in the corresponding info.

So the columns are labeled Name, Address, Telephone etc... Trying to form a client list
When I enter the info in the textbox I need it to send it to the corresponding column in the next available row.
 
Upvote 0
Probably best if you start a new thread for this question.

I'll be glad to respond tonight if you haven't received a response from someone else.
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top