Help needed for textbox to cell copy paste

projester

New Member
Joined
Mar 26, 2010
Messages
2
Hi
I am using Excel 2007 and Vista.

I've been trying to find a way to copy the text from a textbox ("ProjectName") on one worksheet "Data Input" and paste it to a cell in another worksheet "Project Data".

I have the code that activates the text box but I havent been able to find a clear way to copy and past the text from that textbox in the way that I want.

The books I've got don't really seem to address doing this and I haven't been able to find a solution online that has worked.

So far it is just:

Sub Textbox()

Sheets("Data Input").Select
ActiveSheet.ProjectName.Activate


End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I'm not sure if your textbox "ProjectName" is a range (as it seems to be in your code) or an actial TextBox as you're saying it is. So I'm trying to cover both cases:

1) If "ProjectName" is a range:

Without knowing how big the range is I'm using the resize here. If it's just one single cell you can just leave it out. Also i don't know where you want the data on the "Project Data" so I'm supposing you want it starting from the first empty cell on column A. Here's my code:

Code:
Dim rng As Range
Dim Height As Long
Dim Width As Long

'Checks the size of the range:
Set rng = Range("ProjectName")
Height = rng.Rows.Count
Width = rng.Columns.Count

'Finds the first empty cell on Column A on the "Project Data" sheet:
Set rng = Sheets("Project Data").Range("A" & Sheets("Project Data").Rows.Count).End(xlUp).Offset(1, 0)
'Resizes the found range to match the range "ProjectName":
Set rng = rng.Resize(Height, Width)
'Writes the values:
rng.Value = Range("ProjectName").Value

2) If "ProjectName" is a TextBox on your UserForm and you want to write the data to two separate sheets. Once again I'm supposing you want the text to be written on the first empty cell on column A on both sheets (This code needs to be in the UserForm module):

Code:
Private Sub CommandButton1_Click()
'Writes to the first sheet:
Sheets("Data Input").Range("A" & Sheets("Data Input").Rows.Count).End(xlUp).Offset(1, 0).Value = Me.ProjectName.Value
'Writes to the second sheet:
Sheets("Project Data").Range("A" & Sheets("Project Data").Rows.Count).End(xlUp).Offset(1, 0).Value = Me.ProjectName.Value
'Closes the UserForm:
Unload Me

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,946
Messages
6,122,401
Members
449,081
Latest member
JAMES KECULAH

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