Results 1 to 6 of 6

Macro to Add sheet after last sheet

Threaded View

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Macro to Add sheet after last sheet

    I have tried to write code to create a sheet to have the same name as in cell A1 on sheet1 ("Data") and to copy all the values and formats


    For eg if A1 on sheet1 (named "Data") A1 is July-2019 , then sheet "July-2019" is to be created after the last sheet and the data copied and pasted as values and the format also to be the same


    I get a run time error when running the macro

     Sub AddSheet_Names()
      Dim MyCell As Range, MyRange As Range
    
     Set MyRange = Sheets("Data").Range("A1")
     Set MyRange = Range(MyRange, MyRange.End(xlDown))
    
     For Each MyCell In MyRange
     Sheets.Add After:=Sheets(Sheets.Count) 'creates a new worksheet
     Sheets(Sheets.Count).Name = MyCell.Value ' renames the new worksheet
     Next MyCell
    End Sub

    I have attached sample Data

    It would be appreciated if someone could assist me

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro updating after selecting another sheet and back to Macro enabled sheet?
    By Imran Magsi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-29-2016, 04:38 AM
  2. macro to get sum of sheet 1 subtract with sum of sheet 2 and input value of sheet 3
    By danwoltrs in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-15-2015, 04:41 PM
  3. [SOLVED] Macro to copy data from a master sheet to separate sheet as per date using a macro
    By tmaster81 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-23-2014, 08:05 AM
  4. [SOLVED] Macro to Copy Data from one Sheet A to Sheet B based on value in cell on sheet A
    By scass in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2012, 07:21 PM
  5. Replies: 1
    Last Post: 07-30-2012, 02:35 PM
  6. [SOLVED] When sheet is activated, execute macro in other sheet and return to sheet
    By timtim89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-16-2012, 10:50 AM
  7. Macro: Count rows in sheet A, copy count in sheet B, paste offset in sheet A
    By Agent:Orange in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-19-2011, 07:56 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1