Consulting

Results 1 to 6 of 6

Thread: Selecting the next sheet and copying the previous

  1. #1

    Selecting the next sheet and copying the previous

    Hi, I am trying to create a macro to create a new worksheet, copy the previous one, past it into the new one and update the name and date. I recorded the macro and this is what I got:

    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets("2-24").Select
    Cells.Select
    Selection.Copy
    Sheets("Sheet2").Select
    ActiveSheet.Paste
    Range("A5:H379").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("A6").Select

    Here are some problems with it:

    1. It references the name of the previous sheet (sheets("2-24")) and my names will change, I just need it to always select the previous sheet no matter the name.
    2. When pasting the info from the previous sheet, it wants to go to Sheet2, but again, I will be using this in variety of spreadsheets and the newly created tab will not always be Sheet2 - is there anyway to reference the NEW tab that was just created?
    3. Once new sheet is created and the info copied from the previous sheet, I need to update the date - I have not recorded this part. In cell B2 will be today's date and B3 previous date.
    4. Can the macro name my new sheet? the name would the the same date as in cell B3 but in a different format. If the date is 2/25/15, the name of the tab should be 2-25.

    I am using Excell 2010.

    Thanks for any suggestions.

    Radka

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    maybe:
    Sub blah()
    Set oldsht = ActiveSheet
    oldsht.Copy After:=Sheets(Sheets.Count)
    With ActiveSheet
      .Range("A5:H379").ClearContents
      .Range("B2").Value = Date
      oldsht.Range("B2").Copy .Range("B3")
      .Name = Format(.Range("B3").Value, "m-d")
    End With
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Wow, this is perfect. Thank you p45cal!!! I know this is probably totally trivial code to you, but it will make my life so much easier. Thank you, thank you, thank you.

  4. #4
    VBAX Mentor
    Joined
    Feb 2015
    Posts
    395
    Location
    Radka.silva
    This thread looks as if it is solved
    If it is please use thread tools and mark as SOLVED

  5. #5
    VBAX Newbie
    Joined
    Feb 2015
    Posts
    1
    Location
    Does anyone know of code that will automate the creation of a photo album and then copy the slides (excluding the title slide) to new slides in the current presentation?

    If not, anyone interested in writing it for me? Your help will be greatly appreciated! :-)

    DJ
    Are you interested in Testking vcp certification itil? Get our self paced oracle certification ccna and passguideitil study packages to pass your without any difficulty in www.usuhs.mil lsat.

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    post your question in PowerPoint help forum.
    http://www.vbaexpress.com/forum/foru...owerPoint-Help

    click "+ Post New Thread" button to start a new thread. it is in the upper left corner of the page.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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