+ Reply to Thread
Results 1 to 15 of 15

Repeat the same actions for different excel files

  1. #1
    Registered User
    Join Date
    11-29-2021
    Location
    Auckland
    MS-Off Ver
    MS Office mac - 16.48
    Posts
    39

    Repeat the same actions for different excel files

    Hi team!

    I'm working on a project where I get data in the exact same excel format, and in order to process that data I need to perform the exact same steps to each files before I can analyse it. So for instance, for each file I need to hide column C, E, F and G - then I need to filter column D - then I need to sort by descending date from column A and time from column B - etc etc... This doesn't seem very efficient to have to do over and over for each separate file that I get, so I was wondering if there was a way in excel to save all these actions and apply to a file when I open it?

    Thanks in advance!!

    Cheers,
    Titia

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,444

    Re: Repeat the same actions for different excel files

    You need a macro. I'll move this to the VBA section for you.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,630

    Re: Repeat the same actions for different excel files

    You could start by recording a macro while you carry out the actions manually. It will probably need tweaking to make it efficient and generic but it will start you off.

    You can save the macro in your personal macro workbook or just a workbook you will open first.

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    11-29-2021
    Location
    Auckland
    MS-Off Ver
    MS Office mac - 16.48
    Posts
    39

    Re: Repeat the same actions for different excel files

    Thank you TMS, excellent idea, I had no idea of macro's yet.

    I've now tried it several times, and sometimes it works perfectly. However, mostly it come up with Run-time error '9': Subscript out of range.
    So even though every excel will has the exact same format, the length of the columns differs immensely, would that be the issue here?
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: Repeat the same actions for different excel files

    Yeah, that's the trouble with recording Macros - It assumes everything will be the same, every time.

    So, yes different lengths of the Column data etc will matter, and you're using a CSV file for your data - Sheet 1 tends to get named the same as your file name which also won't help.

    Assuming you recorded the Macro you'd have had something like this;

    Please Login or Register  to view this content.
    As you can see you have 'hard coded' Ranges (A2:C1419) which are going to be different and you have the Worksheet name such as "WC2-A" hardcoded - Excel will expect them every time, otherwise it'll give you the 'Subscript out of range' error.

    So, to cut a long story short you need to help Excel understand the differences, and so...

    Please Login or Register  to view this content.
    I've used a variable (LastRow) to hold the number of rows of the current data, and I've renamed the Sheet from the very start.

    The variable then takes the place of the last row number in the code, and I can refer to the sheet I know will exist because I named it as such.

    'Disloe2' - Should work with all your files - HOWEVER - You might need to change the Filter Criteria to what you need it to be - You didn't say so I just choose something,

    Post back if you need more help
    Last edited by AliGW; 02-18-2022 at 09:16 AM. Reason: PLEASE don't quote unnecessarily!

  6. #6
    Registered User
    Join Date
    11-29-2021
    Location
    Auckland
    MS-Off Ver
    MS Office mac - 16.48
    Posts
    39

    Re: Repeat the same actions for different excel files

    Absolutely brilliant!! All excellent advice and I've tried following it, however some commands just don't seem to work (maybe with my version of Excel?)
    For instance it doesn't rename the sheet with this command - Sheet1.Name = "Disloe" ,and the LastRow thing also keeps giving errors so I just opted to go with Range("A:A") etc. Bit sloppy but does the job good enough for me to get the data I need. This is my scribble now (almost no idea what I'm doing, so please be gentle) , please shout if you see big red flags



    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-29-2021
    Location
    Auckland
    MS-Off Ver
    MS Office mac - 16.48
    Posts
    39

    Re: Repeat the same actions for different excel files

    Ok so on the same topic, working with the same data, I was wondering if I can take these wonderful macros a step further?

    I've attached how the original data looks and what I'm trying to get out of it. I need to know the number of long tails recorded per night, which to me seems immensely complicated because there's a change in date during the night and the night sometimes doesn't finish until 7am. I already added the extra column H with a value of 1 next to it, which to me seemed like the easiest way to have excel calculate the sum when I manually select the relevant cells. But it still a lot of work going through all the rows, and has a high rate of human error...

    Not sure if I need to open a new topic for this, please correct me if I do! And again, thank you to everyone willing to give this a look, so far this forum has been extremely helpful to me.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Repeat the same actions for different excel files


    Hi,

    what is the date format within your text files in your last attachment ?

    What is the criteria to reorder the source data to the expected result ?

  9. #9
    Registered User
    Join Date
    11-29-2021
    Location
    Auckland
    MS-Off Ver
    MS Office mac - 16.48
    Posts
    39

    Re: Repeat the same actions for different excel files

    Hi Marc,

    I believe the date format it dd/mm/yyyy
    I hope I'm understanding/answering your question correctly:
    • Order on date
    • Order on time
    • filter out the rows that don't have "Long tail" in column D
    • hide column C, E, F,G
    • ad a "1" to all remaining rows in column H (so all the rows with Long tail)
    • provide a sum off all the "1" in column H that correspond with a 24h period (starting in the evening (PM) and ending in the morning of the next day (AM)

    Does this make sense and is this doable in excel?

    Thanks advance! Again!

  10. #10
    Registered User
    Join Date
    11-29-2021
    Location
    Auckland
    MS-Off Ver
    MS Office mac - 16.48
    Posts
    39

    Re: Repeat the same actions for different excel files

    Also, would it help if I convert this file to an excel file instead of csv? And would that results in data loss?

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Repeat the same actions for different excel files


    It depends on the source and the destination files as your title states for Excel files so .xlsx but this is csv text files within your attachment ?

  12. #12
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Repeat the same actions for different excel files


    And your post #9 explanation does not match your post #7 attachment so difficult to help
    or you are enough confident with your Excel / VBA skills to amend any starting point code any helper can share ? …

  13. #13
    Registered User
    Join Date
    11-29-2021
    Location
    Auckland
    MS-Off Ver
    MS Office mac - 16.48
    Posts
    39

    Re: Repeat the same actions for different excel files

    Oh so sorry, I don't think I can change the title now. The files are always provided in a .csv format, and I don't really care what file it is in the end as long as I get the data out of it that I need.

    I'm not sure how the criteria to reorder the source data to the expected result are really relevant for what I need to explain what I'm after though.
    If you have a look at the WC1-A result.csv‎ file and apply this macro:

    Please Login or Register  to view this content.
    You can see that in I116 and I186 there's a number relating to the sum of the number of "1" in column H. Normally these files are way bigger and have more days, and it takes me quite long time to scroll through and select the cells that are within that 24h period without make mistakes.
    I'm looking for a way for excel to do that for me, and provides me with the sum off the "1" in column H per day, which is a 24h period starting in the pm and finishing in the am.

    Please let me know if that makes sense? It's so hard to explain

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Repeat the same actions for different excel files


    Ok if a source csv text file can contain more than a day then attach such csv text file and accordingly its exact expected resut workbook
    and choose if the final result file is an Excel workbook or a csv text file …

  15. #15
    Registered User
    Join Date
    11-29-2021
    Location
    Auckland
    MS-Off Ver
    MS Office mac - 16.48
    Posts
    39

    Re: Repeat the same actions for different excel files

    I'm sorry Marc, I feel we're on way too different levels here and I can hardly understand what it is you want from me to enable you to help me.

    I'm going to open a new threat on this issue to encourage more advice and different perspectives, but I really appreciate the help you've offered so far. I've learned a lot!

+ 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. F4 Requires Two Actions to Repeat Instead of One
    By WorthPursuit in forum Excel General
    Replies: 3
    Last Post: 03-09-2020, 12:54 AM
  2. Replies: 4
    Last Post: 05-20-2013, 08:31 AM
  3. [SOLVED] Repeat actions in a Loop
    By abduljaleel.mca in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2013, 11:03 AM
  4. Macro doesn't repeat manual actions
    By ddartt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2008, 05:43 AM
  5. Repeat actions not working
    By Ken G. in forum Excel General
    Replies: 1
    Last Post: 07-12-2006, 03:00 AM
  6. [SOLVED] How repeat a task on all files on a floppy drive
    By ED007 in forum Excel General
    Replies: 3
    Last Post: 08-17-2005, 10:05 AM
  7. Repeat Code Repetitive Actions?
    By chris in forum Excel General
    Replies: 2
    Last Post: 02-18-2005, 08:06 PM

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