+ Reply to Thread
Results 1 to 3 of 3

Macro crashing Excel whilst (not) filtering

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,474

    Macro crashing Excel whilst (not) filtering

    Attached workbook goes into non-response mode when asked to set the filter on the DATABASE sheet, and eventually I have to close Excel, but can't see why?

    DATABASE worksheet lists names, test dates and results across four tests for Jan - April.

    Macro needs to start by filtering Col A of the DATABASE by the Name selected from the DropList in C2 of the PERFORMANCE worksheet, then Transpose the dates and scores into Cols C - F of the PERFORMANCE worksheet.
    End result should be as shown in Cols I - M, if Candidate 1 is selected.

    But I can't even get it to complete the first step (Filter the Database to show only the name selected).

    Option Explicit
    Dim f As Long, lngCnt As Long
    Dim rng As Range, cell As Range
    Dim arrList() As String
    Dim ws As Worksheet, ws2 As Worksheet
    
    Sub PlayerPerf()
    
        Set ws = Sheet1
        Set ws2 = Sheet2
        
    'Find last row in Database
        
        With ws2
        f = .Cells(.Rows.Count, "A").End(xlUp).Row
        If f < 2 Then f = 2
        
        Set rng = .Range("A2:A" & f)
    
    'Load values into an array
        lngCnt = 0
            For Each cell In rng
            ReDim Preserve arrList(lngCnt)
            arrList(lngCnt) = cell.Text
            lngCnt = lngCnt + 1
            Next
    
        If .FilterMode Then .ShowAllData
    
        .Range("A2:A" & f).AutoFilter Field:=1, Criteria1:=ws.Cells(2, 3), Operator:=xlFilterValues
    
    End With
    
    End Sub
    All solutions, suggestions and alternatives welcome as ever

    Ochimus
    Attached Files Attached Files
    Last edited by Ochimus; 08-22-2021 at 09:19 PM.

  2. #2
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: Macro crashing Excel whilst (not) filtering

    Please try

    Sub PlayerPerf()
        
    With Sheet2.[A2].CurrentRegion
        .AutoFilter Field:=1, Criteria1:=Sheet1.[c2]
        .Offset(1, 1).Copy
        Sheet1.[c4].PasteSpecial Paste:=xlPasteAll, Transpose:=True
        .AutoFilter
    End With
    
    End Sub
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,474

    Re: Macro crashing Excel whilst (not) filtering

    Bo_Ry

    Many thanks for prompt solution. Oddly enough, don't think I've come across the "Sheet[cellref]" structure before, but will certainly embed it from now on!

    Ochimus

+ 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. Filtering with merged cells whilst displaying all data
    By bambino12345 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-24-2021, 06:39 AM
  2. [SOLVED] VBA to send multiple emails whilst filtering pivot table
    By ChipsSlave in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2017, 06:04 AM
  3. VBA to send multiple emails whilst filtering pivot slicer
    By ChipsSlave in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-22-2017, 02:07 PM
  4. Excel crashing when trying to view code before macro run; not crashing after first run
    By goonerforlyf in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2015, 05:27 PM
  5. Replies: 1
    Last Post: 09-17-2014, 10:52 AM
  6. Programatically Scrolling Whilst Populating Spreadsheet Without Crashing
    By RowanB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-24-2013, 09:47 AM
  7. Program crashing whilst accessing outlook
    By tryer in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-06-2012, 03:14 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