0
votes

So I know the answer to the question How to copy sheets to another workbook using vba? And here is the code I used:

    wb.Worksheets(1).Copy Before:=activeWB.Worksheets("Sheet1")

So from this workbook called "wb", I copy the worksheet within "wb" to a new workbook called"activeWB". The before function place this sheet in front of "Sheet1".

However, I want to place the sheet from "Wb" to "Sheet1", not before or after it. I tried many many methods, but couldn't get this to work. :(

2

2 Answers

1
votes

Have you tried?

wb.WorkSheets(1).UsedRange.Copy activeWB.WorkSheets("Sheet1").Range("A1")
2
votes

Don't overthink this. Copy the sheet. Delete the existing Sheet1. Rename the copied sheet to Sheet1

wb.Worksheets(1).Copy Before:=activeWB.Worksheets(1)
Application.DisplayAlerts = False
activeWB.Worksheets("Sheet1").Delete
Application.DisplayAlerts = True
activeWB.Worksheets(1).Name = "Sheet1"