I am trying to save time inputting data by transferring data from one workbook, into another (preferably, straight onto a userform that I have initiated the copy from).
So I have a button my form which initiates the below;
Sub CopyRangeToAnotherSheet()
Dim wbThis As Workbook
Dim wbTarget As Workbook
With Application
.ScreenUpdating = True
.EnableEvents = False
End With
Set wbThis = Workbooks.Open("SOURCEWORKBOOKPATH")
wbThis.Sheets("Sheet1").Range("CELLNAME").Copy
Set wbTarget = ThisWorkbook
UserForm_Initialize
wbTarget.Forms("UserForm1").Range("DESTFORMFIELD").PasteSpecial
Paste:=xlPasteValues
wbThis.Close
UserForm_Initialize
End Sub
I have managed to copy from one workbook to another workbook fine, however I want the data copied into the form textboxes.
It's erroring on
wbTarget.Forms("UserForm1").Range("DESTFORMFIELD").PasteSpecial
but I can't seem to figure out the syntax.
try it this way.
Store the copied value in a variabe
cell_content = wbThis.Sheets("Sheet1").Range("CELLNAME").Value
UserForm1.DESTFORMFIELD.Value = cell_content
UserForm1.Show
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.