+ Reply to Thread
Results 1 to 23 of 23

Optimize code

  1. #1
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Optimize code

    Hi all, I'm new here and I have a question and I hope you guys could help me out.
    In the code on the on the bottom of this message I'd like to optimize, for example, Somethimes I have 10 PCB-flies (PCBS01-PCBS10), somethimes I get more, for example (PCBS01-PCBS27), is there a way to easily adjust everything by using loops or something? Also every collumn I copy from one file must be placed on the adjacent collumn and at the end I want as you can see have an extra collumn with average, and also one with the stdev. If more info required or if this impossible, please let me know

    Thanks and greetings from Belgium!


    Please Login or Register  to view this content.
    Last edited by arlu1201; 02-05-2014 at 05:59 AM. Reason: Use code tags in future.

  2. #2
    Registered User
    Join Date
    10-03-2010
    Location
    Poland
    MS-Off Ver
    2000 ; 2007
    Posts
    17

    Re: Optimize code

    If u see flickering on the screen I would add at beggining
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    at the end.

  3. #3
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    You may try:
    Please Login or Register  to view this content.
    Last edited by Izandol; 02-05-2014 at 07:46 AM. Reason: Correct mistakes!
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  4. #4
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    Already Big thanks Izandol!

    however when I add the code I get a err on:

    Set wb = Workbooks.Open(Filename:=csPATH & "PCBS01.CSV")

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    My mistake in file path:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    thanks Izandol, should have seen that one too, mybad.


    Workbooks("Dimitri04Feb2014Analysis.xlsx").Range("A1").PasteSpecial Paste:=xlPasteValues, _
    Operation:=xlNone, SkipBlanks:=False, Transpose:=False

    Here I tried several things like this but still not working, "Subscript out of range" Is the problem

    Windows("Dimitri04Feb2014Analysis.xlsx").Column("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False



    edit: maybe because I should change the extension now by .xlsm ?
    Last edited by DarkKnightLupo; 02-05-2014 at 07:26 AM.

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    If file is saved as .xlsm then yes you must change this. If it is file with code we may use better syntax:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    Ok Thanks a lot, it works great now!
    You are a Hero

  9. #9
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    Ok one nore esthetical question,

    Range("B2").Value = "PCBS01"
    Range("B2").AutoFill Destination:=Range("B2:L2"), Type:=xlFillDefault

    L2 is for 11 files, but can you adapt it to the number you modify, for example 27 zithout counting everytime the Range ?

    it is not that important!

  10. #10
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    Of course:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    Hey, I got another interesting question I think,
    Imagine You have files with Names PCBS02, PCBS05, PCBS06, PCBS10 for example, so there is no regular connection and PCBS01, PCBS03, PCBS04, PCBS07 .. does not exist, is it possible to search for the files and putting them next to each other when I set n=10, because now I'll get a err when the file +1 is not there?

  12. #12
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    Do you know the names in advance, or will you only process all CSV files in the folder? Which file must have two columns copied?

  13. #13
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    All the files exist out of three columns, The first one is for every file the same and the second one are the different results. ( so I need the first one, and all the second columns). I dont know the names in advance because they can change from experiment to experiment..., but also the total number of files changes but thats easy to look up.


    To better Explain, S01, S02 is the number of the measurement, So it is possible I measure 10 times in a row the same thing, for example PCB, but it ia also possible I measure first 1 Reference, 3 Pcb, 2 A en 2 B, that woul give me a data set with names REFS01, PCBS02, PCBS03, PCBS04, AS05, AS06, BS07, BS08, You understand what I mean:p

    Then I want in Excel a sheet with PCBS together, another sheet with REFs together, another sheet with As together ...

  14. #14
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    I think I understand. You may try:
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    Ok this works very good, the only problem is that I get trouble calculating the average and the STDEV, originally I should have replaced -11 by -n, but now, -lCounter doesnt works...

  16. #16
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    You may use fixed column to start - I assume column 2:
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    Ok thanks of course ,

    You are a real pro, You really helped me out man, I hope I was not too annoying with stupid questions, Big Thanks o Izandol!

  18. #18
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    You are welcome.

    No annoying at all - questions are good! This is how we all learn.

  19. #19
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    Hi Izandol,

    I'm back again, the code worked pretty well untill I realised It loads in files in a random order instead of the 1->x order ( now it is 1, 12 ,14, 3 ,5 ,... for example)
    \. How can I force the sequence of the files I take my collumns of the way it should be so that first col comes from S01, 2nd from S02, etc...
    Thanks already!

    Here you can find the code:

    Please Login or Register  to view this content.

  20. #20
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    I have not tested:
    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    Hi, no error but it still imports the files in a random order...


    For ease I renamed the files to PCBDRIFTS1 instead of PCBDRIFTS01 and so on..

    Thanks anyhow!

  22. #22
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Optimize code

    For ease I renamed the files to PCBDRIFTS1 instead of PCBDRIFTS01 and so on..
    This will break the sorting because in alpha sort PCBDRIFTS10 will come before PCBDRIFTS2. If you will name the file PCBDRIFTS01, PCBDRIFTS02 et cetera the sort will work.

  23. #23
    Registered User
    Join Date
    02-05-2014
    Location
    Belgium
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Optimize code

    Thank You !! It seems to work fine now!

+ 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. Optimize a slow code...
    By benoitly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2013, 01:44 PM
  2. Optimize code
    By miso.dca in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-08-2011, 03:35 PM
  3. Optimize Alphabetizing VBA Code
    By NewExcelUser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2010, 11:51 PM
  4. How can I optimize/simplify that code ?
    By Grek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2010, 03:38 PM
  5. Optimize VBA code
    By doodlebug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2007, 07:53 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