Macro that copies and paste the sheet to another workbook works on Windows but not on Mac

Zem32619

New Member
Joined
Jul 2, 2021
Messages
29
Office Version
  1. 365
Platform
  1. Windows
Hi Excel Masters.

I need your help for a code that will work for Mac too. Currently, my code works perfectly fine for Windows but not on Mac, specfically in pasting the sheet from one workbook to another workbook. The copy code works, but I am encountering error in pasting it to another sheet. The error is higlighted at "Sheets(2).Select" line. Here's my code:

Sheets(1).Select
Cells.Select
Selection.Copy
ActiveWorkbook.Close SaveChanges:=False

'Adding new sheet and pasting the SB STR to SP STR file


'Sheets.Add After:=Sheets(2)
Sheets(2).Select
Sheets.Add After:=ActiveSheet
'ActiveSheet.Name = "SB"
sheetName = "SB"
Application.CutCopyMode = False
ActiveSheet.Name = sheetName
'ActiveSheet.Paste
Sheets(sheetName).Paste
Range("A1").Select

Looking forward for your help on this. Thank you so much.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
In the 4th line you are closing the workbook and in the 11th line you are selecting sheet2. When you've closed the workbook how can you select the sheet.
 
Upvote 0
Hi shinigamilight, thanks for your reply. In the 4th line I'm closing the workbook that I copied a sheet from and in the 11th line it is selecting the sheet2 of the workbook where the copied sheet is to be pasted. This works perfectly fine on Windows, but not on Mac and the error is on the "Sheets(2).Select" line.
 
Upvote 0
Hi shinigamilight, thanks for your reply. In the 4th line I'm closing the workbook that I copied a sheet from and in the 11th line it is selecting the sheet2 of the workbook where the copied sheet is to be pasted. This works perfectly fine on Windows, but not on Mac and the error is on the "Sheets(2).Select" line.
You're running this code from the workbook you're copying from or from the workbook you're pasting. Because your code doesn't use workbook references it's hard to make out anything. I pasted your code in my workbook and ran it but nothing happened. You don't need select all the cells to copy the sheet, you can directly send the sheet to another workbook using this:

VBA Code:
ActiveWorkbook.Sheets(1).Copy after:=Workbooks(2).Sheets(2)
 
Upvote 0
Hi shinigamilight, I'm running the code on the workbook I'm pasting the sheet. Will try your suggestion and let you how it works. Really appreciate it. Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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