New Sheet is going to the end of sheet list instead of the beginning

alleneure

New Member
Joined
Feb 22, 2023
Messages
17
Office Version
  1. 365
Platform
  1. Windows
I have a macro button that copies the sheet to another sheet and deletes everything from th original to have it blank for the next use. Currently the sheet is going to the end of the lists of sheets but I want it to go to the beginning of the list. My current code is as follows:

VBA Code:
Public Sub CopySheetAndRenameByCell2()
  
Dim wks As Worksheet
  Set wks = ActiveSheet
  ActiveSheet.Copy Before:=Worksheets(Sheets.Count)
  If wks.Range("C6").Value <> "" Then
    On Error Resume Next
    ActiveSheet.Name = wks.Range("C6").Value
  End If
  
   Dim B As Button
        For Each B In ActiveSheet.Buttons
            If B.Caption = "Next MRL" Then
                B.Delete  'Delete the button labeled "Run Macro #1"
            End If
        Next B

  wks.Activate
  
  Sheets("New MRL").Range("c3:c5") = ""
  Sheets("New MRL").Range("c7:c9") = ""
  Sheets("New MRL").Range("c11:d13") = ""
  Sheets("New MRL").Range("c21") = ""
  Sheets("New MRL").Range("c22") = ""
  Sheets("New MRL").Range("c23") = ""
  Sheets("New MRL").Range("c24:c27") = ""
  Sheets("New MRL").Range("d7") = "T or t"
  Sheets("New MRL").Range("c33") = ""
  Sheets("New MRL").Range("c37") = ""
  Sheets("New MRL").Range("h3") = "Must choose for TKPH"
  Sheets("New MRL").Range("h4:h9") = ""
  Sheets("New MRL").Range("k3") = "Choose"
    
   Dim pic As Picture
    
    For Each pic In ActiveSheet.Pictures
        If pic.Name <> "Logo" Then
            pic.Delete
        End If
    Next pic
    

End Sub

I initially had the below part as after and changed it to before and it placed it before all the other sheets in the workbook for one or 2 cycles but then switched back to moving it to the last sheet.
VBA Code:
ActiveSheet.Copy Before:=Worksheets(Sheets.Count)

Thanks for any recommendations or advice.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try this:
VBA Code:
  Set wks = ActiveSheet
  ActiveSheet.Copy Before:=Worksheets(1)                    '<<< MODIFIED LINE
  If wks.Range("C6").Value <> "" Then
 
Upvote 0
Having the value as 1 put it as the first sheet before the template sheet but I changed it to 2 and works like a charm! Thanks so much!
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,836
Members
449,096
Latest member
Erald

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