+ Reply to Thread
Results 1 to 16 of 16

VBA Code running very slow to seperate 250 rows into 5 categories

  1. #1
    Registered User
    Join Date
    09-29-2015
    Location
    Gainesville, FL
    MS-Off Ver
    2013
    Posts
    7

    VBA Code running very slow to seperate 250 rows into 5 categories

    The basics of this code are to examine a spreadsheet by multiple criteria and separate it into 5 categories. Then copy 4 of the categories and only certain column of data to another spreadsheet sorting it into 4 segregated areas on the spreadsheet, inserting rows as needed. It runs as it is but takes up to a minute to make it through the 250 rows and is inserting multiple blank rows and over righting other rows. What am I missing please


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Hareborn; 09-29-2015 at 02:57 PM.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    Hi,

    Please edit your post and use code tags as required by our http://www.excelforum.com/forum-rule...rum-rules.html it really improves readability

    Consider also posting sample workbook to play with.

    Just at the first glance - there are many
    Please Login or Register  to view this content.
    commands - they can be quite time-consumming, especially if there is a lot of data below/above the range.
    Best Regards,

    Kaper

  3. #3
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  4. #4
    Registered User
    Join Date
    09-29-2015
    Location
    Gainesville, FL
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    Sorry about the format, I fixed it.

  5. #5
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    What should we do in this form before clicking the make ready button, to duplicate your issue?

  6. #6
    Registered User
    Join Date
    09-29-2015
    Location
    Gainesville, FL
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    Nothing it was the processing time of the button that was the primary issue. I have resolved that though by moving the "Unload Me" to the end of the process. I still have the issue of the form populating correctly. If you look at the form before button push you will see the layout. After button push it is a garbled mess.

  7. #7
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    You have a very busy workbook. You don't explain where to find the code in your first post. I found it because I did a search for the name of the procedure.

    You have a lot of stuff in this workbook and to just say push a button and you will see a jumbled mess doesn't help me.
    If we are talking about the layout form the only way I know to run it is by bringing it up in the VBE and choosing F5, then clicking the make ready button and then the form disappears, so whatever it is I'm supposed to see that's a garbled mess isn't apparent to me.

  8. #8
    Registered User
    Join Date
    09-29-2015
    Location
    Gainesville, FL
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    Sorry, I am not articulating myself very well. The workbook has 3 sheets, Start, Make Ready, Apartments. The Start sheet has a "Start" command button to pull the userform up. On the userform is the "Make Ready" command button in question. It's function is to populate the "Make Ready" sheet with the appropriate apartment info sorted into the correct areas. This workbook also has 7 other sheets that will all work in the exact same manner but I simplified the workbook to post it on line.

  9. #9
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    Okay so I open the workbook, I push the start button, the form opens I push make ready button the form closes and I'm not sure what I'm supposed to be seeing that's a garbled mess.

  10. #10
    Registered User
    Join Date
    09-29-2015
    Location
    Gainesville, FL
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    The garbled mess is the "Make Ready" sheet. It is broken into 4 different sections and each section is broken between apartment size. The code should be searching the "Apartment" sheet for each of the 5 categorizes then inserting a row under the appropriate header row on the "Make Ready" sheet and coping the appropriate columns over. The "Make Ready" sheet is designed the be exported as a PDF to be printed and needs to be in an exact layout. If you look at the "Make Ready" sheet on the uploaded file before the userform command button is pushed you can see the format as it should be laid out.

  11. #11
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    That's the kind of explanation I'm looking for. I'd be happy to take a look at it. I'm busy right now, so give me some time.

  12. #12
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    You have a seriously complicated worksheet here.
    I'm trying to step through your F row loop code to see what's going on, but this function.
    Please Login or Register  to view this content.
    keeps getting triggered and then my Excel crashes. If you wrote this code and these API functions yourself I would think you are more than capable of stepping through this code and seeing what the values are and why it's doing what it's doing. If this function is triggering on every line that's probably a good clue as to why your code is so slow, as to what's going on with your other sheet I would suggest stepping through line by line and seeing what is happening.

  13. #13
    Registered User
    Join Date
    09-29-2015
    Location
    Gainesville, FL
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    I'm not a novice but everything I've learned has been through trial and error. The mouse function I got online, I've never worked in that area and had no idea how to do it. As for stepping though my process I tried that. But I'm not understanding why when the code says "MR.Cells(MNoticeMain, 1).Offset(-1).EntireRow.Insert" it offsets -2 once and -1 the next. Or when it scans every row on apartment sheet it inserts the row on the make ready sheet but doesn't copy the data. I'm missing something and I am lost.

  14. #14
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    MR.Cells(MNoticeMain, 1).Offset(-1).EntireRow.Insert" it offsets -2 once and -1 the next
    It's adding one row each time and it adds the row offset -1 from the current value of MNoticeMain. You have eight lines that insert rows. I put a break point on each line just to make sure it was stopping and I ran through the loop line by line several times. MNoticeMain was always 25 each time it ran and it always inserted a row above. When you insert a row above, what happens is the row appears to be pushed down. I noticed that only one of the several times that I ran the code line by line did any data appear. The data was below the blue line labeled 2 bedroom and the data was 1614F 2X1 Up 9/14/2001 Not Ready, this data appeared on one of the first times I ran the code and then the code just kept adding rows and I didn't see any data being filled in.
    Last edited by skywriter; 09-30-2015 at 11:32 AM.

  15. #15
    Registered User
    Join Date
    09-29-2015
    Location
    Gainesville, FL
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    Skywriter that was the kick in the teeth I needed. The row keys I am using (MNoticeMain is one of them) change location every time the loop runs and a row gets added. I had placed the keys outside the loop which was causing them to find their position once and the loop to keep over writing on itself. I moved them into the loop so that they get rechecked each time the loop runs and it works great now, Thank you.
    Last edited by Hareborn; 09-30-2015 at 05:23 AM.

  16. #16
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: VBA Code running very slow to seperate 250 rows into 5 categories

    You're welcome.

    Please click the Thread Tools drop down box above your first post and choose solved.

+ 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. code running to slow and to long
    By Pilot5000 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-03-2015, 05:39 AM
  2. Slow running Code
    By Ausadian in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-25-2015, 04:41 PM
  3. Slow running code
    By phil2006 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-13-2013, 08:02 AM
  4. vba code running too slow
    By hitsujicute in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2013, 06:00 PM
  5. VBA Code running very slow. Need help
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-21-2013, 02:13 PM
  6. Slow running code
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-06-2008, 12:49 PM
  7. Code running slow
    By lou031205 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-08-2007, 12:20 PM

Tags for this Thread

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