Results 1 to 7 of 7

VBA Advanced Filter causing Excel file to corrupt...

Threaded View

  1. #1
    Registered User
    Join Date
    04-24-2013
    Location
    Northampton,England
    MS-Off Ver
    2010
    Posts
    8

    VBA Advanced Filter causing Excel file to corrupt...

    Hi Fellow Excel enthusiasts

    I have a workbook with a worksheet containing a single table of data. I am trying to write VBA to perform an advanced filter and to filter the results from applying the search criteria to another worksheet contained in the same workbook.

    Here is the Code:-
    Option Explicit

    Private Sub Dyno_Range1()
    Dim LastRow As Long
    LastRow = Sheet4.Range("Q" & Rows.Count).End(xlUp).Row
    Sheet4.Range("a3:z" & LastRow).Name = "Data"
    End Sub

    Private Sub Dyno_Range21()
    Dim LastRow As Long
    LastRow = Sheet33.Range("m" & Rows.Count).End(xlUp).Row
    Sheet33.Range("a6:r" & LastRow).Name = "_Depreciation"
    End Sub

    Private Sub Filter_Depreciation()
    '
    ' Advanced Filter on tab depreciation
    '
    On Error GoTo ErrHandler
    Call Dyno_Range1
    Sheets("Depreciation").Range("E17").Select
    Range("Data").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
    "E1:F2"), CopyToRange:=Sheets("Depreciation").Range("A6:r6"), Unique:=False
    Range("k7").Select
    ActiveWorkbook.Worksheets("Depreciation").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Depreciation").Sort.SortFields.Add Key:=Range("M7"), _
    SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    Call Dyno_Range21
    Range("_Depreciation").Select
    ActiveWorkbook.Worksheets("Depreciation").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Depreciation").Sort.SortFields.Add Key:=Range( _
    "k:k"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.Worksheets("Depreciation").Sort
    .SetRange Range("_Depreciation")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    ActiveWindow.SmallScroll Down:=12
    ActiveSheet.PageSetup.PrintArea = Selection.Address
    ErrHandler:
    On Error Resume Next
    End Sub
    After I run the code and save the workbook down and then open I am getting a warning message that reads "We found a problem with some content in "filename.xlsm". Do you want to try to recover as mush as we can? If you trust the source of this workbook click yes".

    If I click yes the workbook opens. Phew. If I go to the Name Manager and delete the name ranges and then save and close and reopen the issue goes away.

    I think the problem stems with my code for advanced filter when the search has no data values in the main data table.

    I would really value any help/comments to fix this.

    Thanks in advance

    Pablos
    Last edited by Pablos690_1; 02-21-2016 at 11:38 AM. Reason: added workbook

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Run advanced filter after opening the file
    By intexxx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-17-2014, 10:35 AM
  2. advanced filter - button to re apply advanced filter across multiple sheets
    By motmac87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2013, 11:16 PM
  3. Corrupt Excel File? <## NASCA DRM FILE - VER1.00 ##>
    By Testrider in forum Excel General
    Replies: 3
    Last Post: 11-29-2011, 06:01 PM
  4. Excel 2007 : Password causing corrupt files
    By JimBobBowie in forum Excel General
    Replies: 0
    Last Post: 10-12-2011, 07:03 AM
  5. Replies: 2
    Last Post: 04-16-2011, 09:29 PM
  6. Excel file merged to WP Data file goes corrupt
    By plynn in forum Excel General
    Replies: 0
    Last Post: 05-30-2007, 11:33 AM
  7. [SOLVED] Corrupt Excel File
    By Hervinder in forum Excel General
    Replies: 1
    Last Post: 06-13-2006, 08:15 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