Sunline
Well-known Member
- Joined
- Oct 6, 2007
- Messages
- 697
Hello all ,
I have this macro that PeterSS wrote for me .
It works perfectly for two other macros I use where I was able to change the
range and case .
It worked originally when range was col V and deleting all except "1", "1"
It also worked originally when range was col O and deleting all except "Mdn"
But I can not get it work in range E and delete all except Matamata .
I am getting yellow highlite in macro as error .
Not sure at all what to change .
Thanks .
I have this macro that PeterSS wrote for me .
It works perfectly for two other macros I use where I was able to change the
range and case .
It worked originally when range was col V and deleting all except "1", "1"
It also worked originally when range was col O and deleting all except "Mdn"
But I can not get it work in range E and delete all except Matamata .
I am getting yellow highlite in macro as error .
Not sure at all what to change .
Thanks .
Excel Workbook | |||
---|---|---|---|
A | |||
1 | Sub Del_Rows() | ||
2 | Dim lr As Long, lc As Long, i As Long, rws As Long | ||
3 | Dim aCol, tmp | ||
4 | |||
5 | lr = Range("E" & Rows.Count).End(xlUp).Row | ||
6 | lc = Cells(1, Columns.Count).End(xlToLeft).Column | ||
7 | aCol = Range("E2:E" & lr).Value | ||
8 | ReDim tmp(1 To lr - 1, 1 To 1) | ||
9 | For i = 1 To lr - 1 | ||
10 | Select Case UCase(aCol(i, 1)) | ||
11 | Case "Matamata Raceway" | ||
12 | |||
13 | Case Else | ||
14 | rws = rws + 1 | ||
15 | tmp(i, 1) = 1 | ||
16 | End Select | ||
17 | Next i | ||
18 | If rws > 0 Then | ||
19 | Application.ScreenUpdating = False | ||
20 | Application.Calculation = xlCalculationManual | ||
21 | Application.EnableEvents = False | ||
22 | With Range("A2").Resize(lr - 1) | ||
23 | .Offset(, lc).Value = tmp | ||
24 | .Resize(, lc + 1).Sort Key1:=.Cells(1, lc + 1), _ | ||
25 | Order1:=xlAscending, Header:=xlNo | ||
26 | .Resize(rws).EntireRow.Delete | ||
27 | .Offset(, lc).ClearContents | ||
28 | End With | ||
29 | Application.EnableEvents = True | ||
30 | Application.Calculation = xlCalculationAutomatic | ||
31 | Application.ScreenUpdating = True | ||
32 | End If | ||
33 | MsgBox "Done" | ||
34 | End Sub | ||
Sheet1 |