Home Excel Powerpoint Word Outlook Error Codes

VBA Useful Codes

Welcome to the World of VBA
Home > VBAUsefulCodes

Excel Macro to copy a worksheet within same workbook

Using this example, you can copy an existing worksheet in a workbook at any given postition like at the beginnig, end or second etc. positions.

Sub CopySheet()

Dim wb As Workbook
Dim sh As Worksheet

Dim newSheetName As String
newSheetName = "newsheetname"

Dim fPath As String

fPath = "C:\myfile.xlsx"
Set wb = workbooks.Open(Filename:=fPath)
' make a copy the first sheet
Set sh = wb.Worksheets(1)
' Copy the worksheet at first position
sh.Copy Before:=Sheets(1)

' Copy the worksheet at last position
sh.Copy After:=Sheets(Sheets.Count)
End Sub


Enter your e-mail below and get notified on the latest blog posts.


VBA Outlook KPI Excel Alt+F11 Dashboards Macros Recording Graphs Automation Developer WaterFall Powerpoint Charts Pivot Tables Forecast Charts

Follow Us