+ Reply to Thread
Results 1 to 7 of 7

Loop - Shorten my code

  1. #1
    Registered User
    Join Date
    05-21-2014
    Posts
    7

    Loop - Shorten my code

    Hello,
    i have got several stock data sets and would like to delete automatically every date with an volume of zero.
    I have for every stock another loop, is it possible to shorten this? By now I have only 3 stocks that makes it easy to handle, but i assume that it will be confusing with more stocks as I have to add another loop for every stock.

    The code is part of an portfolio optimization code, I'm starting to set up...
    Please Login or Register  to view this content.

    Thank you very much for your help!

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Loop - Shorten my code

    Something like:
    Please Login or Register  to view this content.
    replace activeworkbook.sheets with the collection of sheets you want to apply it to or put a test in to skip certain sheets.

    Note - I changed your code to loop backwards, so that it won't skip rows (i.e. if you delete row 5, row 6 becomes row 5, but the i variable will still become row 6 the next time, so what was row 6 is effectively skipped

  3. #3
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: Loop - Shorten my code

    It is possible to shorten. Are wsBMW, wsBASF etc are worksheets? Can you upload the workbook?

  4. #4
    Registered User
    Join Date
    05-21-2014
    Posts
    7

    Re: Loop - Shorten my code

    Hello,

    thanks for your quick replys.
    Here is my workbook:http://www.herber.de/bbs/user/91168.xlsm

  5. #5
    Registered User
    Join Date
    05-21-2014
    Posts
    7

    Re: Loop - Shorten my code

    Quote Originally Posted by ragulduy View Post
    Something like:
    Please Login or Register  to view this content.
    replace activeworkbook.sheets with the collection of sheets you want to apply it to or put a test in to skip certain sheets.

    Note - I changed your code to loop backwards, so that it won't skip rows (i.e. if you delete row 5, row 6 becomes row 5, but the i variable will still become row 6 the next time, so what was row 6 is effectively skipped
    Doesn't work with me...VBA is marking
    .Rows(i)
    and says Error at compiling: incorrect or inadaequalty defined "reference" --> rough translation
    Last edited by mibikeks; 06-18-2014 at 02:34 PM.

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Loop - Shorten my code

    sorry, it should be ws.rows(I).delete

  7. #7
    Registered User
    Join Date
    05-21-2014
    Posts
    7

    Re: Loop - Shorten my code

    Well,
    thanks for your help! My code is running but it's not working
    Please Login or Register  to view this content.
    I tried it, but it doesn't delete anything in my Excel-Worksheet. I have attached my file: http://www.herber.de/bbs/user/91195.xlsm

    Thank you very much for your help!

+ 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. Loop to shorten repetitive and long code?
    By humboldtguy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-16-2013, 03:29 AM
  2. Create a loop by defining X as integer, to shorten length of code
    By ahmerjaved in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-11-2013, 01:11 PM
  3. [SOLVED] Very inefficient code because of different sizes of arrays, how do i shorten my code?
    By Brammer88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 04:49 PM
  4. [SOLVED] Shorten up som sheets-kode maby a loop !
    By excelent in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-05-2006, 04:00 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