VBA> Copy data from open WB to a closed one + transpose

williamsacc

New Member
Joined
Apr 27, 2018
Messages
1
Hello everyone,

I am just starting to learn VBA code so please be patient with me. There is a form that my colleagues need to fill out and submit to a master workbook. I would like their answers to be pasted into the master file transposed. Basically, I need a code that will copy a specified range of answers in an open workbook and paste into the next available line in a closed workbook transposed (also saving and closing that workbook) when they hit a submission button. Right now, I have a code that will copy a range and paste into a closed work book however, it is not transposing. I have tried several things at the end of my pasting line and I keep erroring out.

Can someone help me with the code to transpose? Also, any instruction on how to make this process run by clicking a button would be great.

Thank you!!

Sub Submittodatabase()

Range("B7:B15").Copy
Dim xl0 As New Excel.Application
Dim xlw As New Excel.Workbook
Set xlw = xl0.Workbooks.Open("C:\Users\sabuali\Documents\Contract Review\Database.xlsx")
xl0.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
xlw.Save
xlw.Close
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try
Code:
xlw.Sheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlvalues, Transpose:=True
 
Upvote 0
Also, any instruction on how to make this process run by clicking a button would be great

To add a button to run the macro
On Developer tab \ Insert \ select button at top
Assign macro popup appears automatically
Select Submittodatabase
Click OK
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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