+ Reply to Thread
Results 1 to 14 of 14

Macro to select all, delete all, paste, insert formula and drag it down

  1. #1
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Macro to select all, delete all, paste, insert formula and drag it down

    Hi All,

    Can someone please help me on writing the macro below? Steps are:
    1) Select all
    2) Delete
    3) Paste
    4) Insert in E2 formula =CONCATENATE(YEAR(D2),"/",CHOOSE(MONTH(D2),"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"))
    5) Drag it down

    Thanks,

    Rick

  2. #2
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Record your steps and you will have your macro. We can't write one based on your list of steps as the list makes no sense.

    1) Select all
    Please Login or Register  to view this content.
    This will select all

    2) Delete
    Please Login or Register  to view this content.
    That's your sheet wiped

    3) Paste
    Guaranteed to get an error here as you haven't copied anything

    4) Insert formula.
    D2 is empty as you have deleted everything on your sheet

    5) Drag it down
    How far? Your sheet is empty.
    Frob first, tweak later

  3. #3
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Quote Originally Posted by Neil_ View Post
    3) Paste
    Guaranteed to get an error here as you haven't copied anything

    4) Insert formula.
    D2 is empty as you have deleted everything on your sheet

    5) Drag it down
    How far? Your sheet is empty.
    Hi Neil_,

    Thanks for your reply.

    Ok, will try to make things more clear now:

    3) Before running the macro, assume I already have copied something from another sheet, so just need to be pasted in A1;

    4) This step is correct. After the step 3 (paste) I have data in the sheet. Column D is the first empty column, and that's where the formula should be pasted;

    5) Drag down up to the last populated cell in column C.

    Thanks mate!

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Does this help?

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Quote Originally Posted by JOHN H. DAVIS View Post
    Does this help?

    Please Login or Register  to view this content.
    Hi JOHN H. DAVIS, thanks for your reply.

    Ok, I have done the macro below, but it's not working because when it selects and deletes data in the activesheet, it also unselect what I have copied before running the macro in a second workbook.

    So there is anyway to add in the macro, after SelectionDelete, to go to the "Received" workbook and select all, and then go back to the "PSI" workbook and paste into A1?

    Steps would be:
    1) Select all
    2) Delete
    3) Go to "Received.xls" workbook, select all and copy
    4) Go back to "PSI.xlms" workbook and paste it in A1
    5) Insert in E2 formula =CONCATENATE(YEAR(D2),"/",CHOOSE(MONTH(D2),"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"))
    5) Drag it down until last cell in column D

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Up!

    Can someone please help me with the above?

    Thanks!

  7. #7
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Up!

    Can someone please help me with the above?

    Thanks!

  8. #8
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Up. If someone could help me would be great.

    Thanks,

  9. #9
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Still hoping someone can give me a hand...

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Try:

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Quote Originally Posted by JOHN H. DAVIS View Post
    Try:

    Please Login or Register  to view this content.
    Hi JOHN H. DAVIS,

    That's great, thanks for that.

    Just wondering one thing:

    Trying to replicate this macro to others workbooks, but these workbooks have random names (because they are in a temp location in our email server). So I was wondering if there is a way to access "the other" workbook without actually naming it?

    For example, the above macro is copying from "Receiving.xlsx", but what if it was a random name, like "~6547954.xlsx"? Is there a way to copy from a second workbook without actually naming it?

    Thanks

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    If you open the first workbook. And next open the second workbook. Then you can either refer to the second workbook as:

    Please Login or Register  to view this content.
    If you have created a Personal.xlsb

    Or

    Please Login or Register  to view this content.
    If you haven't. Hope that helps.

  13. #13
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    Beautiful! Thank you very much my friend!

  14. #14
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to select all, delete all, paste, insert formula and drag it down

    You're welcome. Glad to help out and thanks for the feedback and the reps.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to drag formula and paste values
    By ricdamiani in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-05-2016, 12:25 AM
  2. Drag Paste a formula in reverse.
    By cng in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-20-2016, 05:09 AM
  3. Formula will not drag down or work with copy/paste
    By Victoria G in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 03-09-2015, 07:36 AM
  4. Replies: 1
    Last Post: 10-05-2014, 12:28 PM
  5. Macro to Copy Values, Insert Row, Paste in Another, Delete Original Data
    By JimPDX in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-23-2013, 05:35 AM
  6. [SOLVED] Need Macro to select and copy data, paste it to a new location, then delete the old row
    By summerela in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 09-25-2012, 05:22 PM
  7. Macro regarding copy cut paste drag
    By Shaky Jake in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2012, 08:38 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