Copy Different Ranges in Local Workbook, Paste & Transpose in another Workbook on Office 365

foratoms

New Member
Joined
Nov 12, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi,

Please I am new to VBA. I have two worksheets. One on my laptop (and workmates. clones) and the other on office 365 Onedrive. when my colleagues fill their respective workbooks each on their systems and click a submit button, the data in the selected range is pasted in the Onedrive worksheet (in a transposed and rearranged form. So the desired user can just print or export as PDF and send to the concerned officer.

Source Worksheet A: name ""Menu-BEtest.xlsm" Sheet Name "MenuCenter"

1605184044083.png

I want the source data in C1, F1, C5:G6 and C9:G10 copied in the destination as shown below and then the details filled in the range above cleared, then finally a pop up that "Your Booking has been successfully recorded!"

My problem is how to specify the rearrangement as shown below

DESTINATION: Name "Tracking Spreadsheet.xlsx" Worksheet name "data"
1605184108276.png


My code:
VBA Code:
1 Option Explicit
2. Private Sub cmdAdd_Click()
3 'Change Workbook
4 Dim iRow As Long
5 Dim cwb As Workbook ' cloud workbook
6 Dim dwb As Workbook  ' Desktop Workbook
7 Dim wsCopy As Worksheet
8 Dim wsDest As Worksheet
9 Dim lCopyLastRow As Long
10 Dim lDestLastRow As Long
11 Set wsCopy = Workbooks("MeNU.BEtest.xlsm").Worksheets("MenuCenter")
12 Set wsDest = Workbooks("Tracking Spreadsheet.xlsx").Worksheets("Data")
13 Set cwb = Workbooks.Open("[URL]https://iheightplc.my.sharepoint.com/personal/...../Tracking[/URL] Spreadsheet.xlsx")
14    'Determine emptyRow
15        iRow = WorksheetFunction.CountA(cwb.Sheets("data").Range("A:A")) + 1
16        'lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "A").End(xlUp).Row
17.With cwb.Sheets("data")
18  'wsCopy.Range("C23:G" & lCopyLastRow).Copy _
19  'wsDest.Range("A" & lDestLastRow)
20 End With
21 ActiveWorkbook.Save
22 ActiveWindow.Close
23   MsgBox "Congratulations " & Application.UserName & _
24           vbNewLine & "Your Booking has been successfully recorded!", _
25            vbInformation, "Success!"
 26        Range("C25:G26").ClearContents
 27 Range("C29:G30").ClearContents
28          End Sub


The destination table is opened and i get this error with no data pasted and the destination folder remaining open instead of closing
1605184268834.png


How will the code be able to, in logical order;
1. properly open the destination worksheet,
2 paste in desired order,
3 close the destination,
4 pop up message and
5.then clear the source range.

Please assist me
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,214,913
Messages
6,122,207
Members
449,074
Latest member
cancansova

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