VBA Code Locks up Excel

JamesHayek

New Member
Joined
May 24, 2016
Messages
20
Hello All, hope all is well!

I had an issue where I needed to filter the highest value, given a set.

That set was defined by rows equaling each other. For any given lat/long/timestamp I am given up to five values.
I have used a function to identify which item in each set has the highest value. This works.

The function is:
VBA Code:
=IF(F13=MAX(IF($A:$A=A13, $F:$F)), "Yes", "No")

I wrote a VBA to automate it. It worked initially, then started to freeze my unit. I am not sure why.

I have tried to include a test file, but .CSV and .ZIP files are not uploadable. So, I pasted a link below the code.

Any help would be greatly appreciated.

VBA Code:
Sub FilterRSRP_From_CSV()

    Application.ScreenUpdating = False

    Application.DisplayAlerts = False 'switching off the alert button
    
    ActiveSheet.Name = "OriginalData"
    
    Range("I8").Select
    Selection.FormulaArray = "=IF(RC[-3]=MAX(IF(C1=RC[-8], C6)), ""Yes"", ""No"")"
    Selection.AutoFill Destination:=Range("I8:I30000"), Type:=xlFillDefault
    Range("I8:I50000").Select

    Columns("I:I").Select
    Selection.AutoFilter
    ActiveSheet.Range("$I$1:$I$50000").AutoFilter Field:=1, Criteria1:="Yes"
    Cells.Select
    Range("L19").Activate
    Selection.Copy
    
    Sheets.Add After:=ActiveSheet
    ActiveSheet.Name = "FilteredData"
    ActiveSheet.Paste
    Application.CutCopyMode = False
    
    Columns("I:I").Select
    Selection.Delete Shift:=xlToLeft
    
    Worksheets("OriginalData").Delete
    
    ActiveWorkbook.Save

    Workbooks.Close
    
End Sub


CSV File
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
UPDATE: When I step though each line using F8, I see theres a lag in the line "Selection.AutoFill Destination:=Range("I8:I30000"), Type:=xlFillDefault", but it chugs through. When I run the script, the Excel sheet locks up on me (Flashes).
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top