PDA

View Full Version : Paste the content from Excel to UserForm -> TextBox



sj72053
08-19-2008, 10:39 PM
Hi,
On click of Button, UserForm is displayed with TextBox1
how can we paste the Range of values A1:D15 from Excel-> Sheet1 into TextBox1

Range("A1:D15").Select
Selection.Copy

so on click of a button a UserForm with TextBox should be displayed with the content from A1:D15 from Excel-Sheet1 ....

Jan Karel Pieterse
08-20-2008, 01:06 AM
In the initialisation code of the userform:


Dim oCell as Range
Dim sText As String
For Each oCell in Range("A1:A15")
sText=sText & oCell.Value & vbNewLine
Next
TextBox1.Value=sText

sj72053
08-20-2008, 01:37 AM
Thank you Jan Karel ... it's working

sj72053
08-20-2008, 02:02 AM
Hi,

For Each oCell in Range("A1:A15") -> will select the Active Sheet {Sheet1} Range ("A1: A15") but can we select the Range("A1:A15") for Sheet3 of Workbook

Jan Karel Pieterse
08-20-2008, 04:47 AM
Of cours, replace "Range" with Worksheets("Sheet1").Range....
This assumes that you want to work with Sheet1 in the active workbook. If you want to ensure it uses the workbook with the code, you use:

ThisWorkbook.Worksheets(.......

And if it is a specific other workbook:

Workbooks("Book.xls").Worksheets(.....