+ Reply to Thread
Results 1 to 5 of 5

Macro Freezing during Copy procedure

Hybrid View

jacob@thepenpoint Macro Freezing during Copy... 04-16-2012, 06:40 PM
rylo Re: Macro Freezing during... 04-16-2012, 07:29 PM
jacob@thepenpoint Re: Macro Freezing during... 04-17-2012, 08:06 AM
rylo Re: Macro Freezing during... 04-17-2012, 06:21 PM
jacob@thepenpoint Re: Macro Freezing during... 04-18-2012, 10:45 AM
  1. #1
    Forum Contributor
    Join Date
    10-16-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2003, 2010
    Posts
    151

    Macro Freezing during Copy procedure

    Hi all

    I have been working a bit at a time on this macro for the past several weeks, and it actually worked (yea me!) Anyway, last week for reasons of its own, it decided to stop working and freeze not only the macro execution, but excel itself, to the point I had to use Ctrl+Alt+Del to break it up. I put in an on error goto with a snappy message to let me know that it didn't work, but it doesn't even do that.

    Stepping through the code, this is the place (very near the beginning) that it wants to go berserk:
    Sub Macro2()
    
    Dim datebreak As Variant
    
    datebreak = Now() - 180
        Sheets("Data Staging").Select
        Cells.Select
        Selection.Delete Shift:=xlUp
        Sheets("Pivot Table").Select
        ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
    '
    '   yada yada yada clickity clickity clickity put in header row
    '
        lrow = Worksheets("Pivot Table").Range("A" & Rows.Count).End(xlUp).Row
    For i = 4 To lrow
        If Worksheets("Pivot Table").Range("A" & i).Value >= datebreak Then
        Worksheets("Pivot Table").Range("A" & i & ":P" & i).Copy _
            Worksheets("Data Staging").Range("A" & Rows.Count).End _
                (xlUp).Offset(1, 0)
        End If
    Next i
    End Sub
    The purpose is to select records encompassing the past 6 months (give or take), from there it will perform some analysis and formatting to give management basically a dashboard showing performance over the last 6 months from the day it is run.

    Most of the entire macro (and it is about 14pgs long printed) was created using the macro recorder, then trying to file down the rough edges and get rid of anything that it didn't need. I am sure it is not the most streamlined macro out there, but it has truly been a stretch for me. I am sure there is a better way of getting these records, but it eludes me.

    I would appreciate any help or suggestions anyone could provide.

    Thanks
    Jacob Albers
    Excel 2003 & 2010

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro Freezing during Copy procedure

    Hi

    Why don't you use the filter on the pivot table so that it only has the relevant data. Presumably your column A has some form of date, so you should be able to cycle through the pivottable filed items, and if it is within your date range, then make the item visible. Then you should be able to just copy / value paste the entire pivot table.

    rylo

  3. #3
    Forum Contributor
    Join Date
    10-16-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2003, 2010
    Posts
    151

    Re: Macro Freezing during Copy procedure

    Thanks Rylo

    Initially it was my intention to filter the pivot table to date then copy the entire table like you suggest, but I wasn't able to figure out a convenient way to filter the dates. I will go back and work with the pivot table to see if I can accomplish that without having to tick off 600 or so check boxes as that would certainly be faster than the way this runs.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro Freezing during Copy procedure

    Hi

    One easy way to get some code is to do a recorder of turning on or off some of the items for the filter. This will give you the structure of the code. Then all you do is make any date that is => date-180 visible, and the rest not visible.

    rylo

  5. #5
    Forum Contributor
    Join Date
    10-16-2010
    Location
    Memphis, TN
    MS-Off Ver
    Excel 2003, 2010
    Posts
    151

    Re: Macro Freezing during Copy procedure

    Thanks Rylo

    I will try approaching it from that angle. I also thought of using a helper column with an IF THEN formula to identify the records I need then filtering on that and copying the resulting block. Not sure if that will be any quicker than what I am currently doing, but it seems a bit more straightforward.

    Seems like there is always more than one way to skin a cat, the trick lies in catching the cat!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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