Hi and welcome to Mr Excel.
So you can have up to 15 thousand records. Deleting is always going to be a very slow process.
So the following macro does not delete records, what it does is select the records you need. The result puts it in columns E through G.
That way you keep the original data and the new data.
But if you still don't want the originals, then just change in the macro, in the last line "E2" to "A2" and that's it.
Range("E2").Resize(UBound(b, 1), 3).Value = b
Copy all the code into a new module:
VBA Code:
Option Explicit
Dim y As Long
Sub remove_Unneeded_rows()
Dim dic As Object
Dim a As Variant, b As Variant
Dim i As Long, j As Long
Dim ant As String
Dim first0 As Boolean
a = Range("A2:C" & Range("C" & Rows.Count).End(3).Row + 1)
ReDim b(1 To UBound(a, 1), 1 To 3)
Set dic = CreateObject("Scripting.Dictionary")
Range("E:G").ClearContents
ant = a(1, 2)
y = 0
For i = 1 To UBound(a, 1)
If a(i, 2) = ant Then
If Not dic.exists(a(i, 2)) Then
Call adding(dic, a, b, i) 'first point
first0 = False
Else
If a(i, 3) = 0 And first0 = False Then
first0 = True
Call adding(dic, a, b, i) 'first "0"
End If
End If
Else
'For the last point the parameter that is sent is 'j'
j = i - 1
If dic(a(j, 2)) <> j Then
Call adding(dic, a, b, j) 'Last point
End If
'Last point
dic.RemoveAll
If a(i, 2) <> "" Then
Call adding(dic, a, b, i) 'first poin
first0 = False
End If
End If
ant = a(i, 2)
Range("E2").Resize(UBound(b, 1), 3).Value = b
Next
Range("E2").Resize(UBound(b, 1), 3).Value = b
End Sub
Sub adding(dic, a, b, i)
'Adding data to the output array
y = y + 1
dic(a(i, 2)) = i
b(y, 1) = a(i, 1)
b(y, 2) = a(i, 2)
b(y, 3) = a(i, 3)
End Sub
-------
HOW TO INSTALL MACROs
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (
remove_Unneeded_rows) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
-------
NOTE XL2BB:
For the future, it would help greatly if you could give us the sample data in a form that we can copy to test with, rather that a picture.
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here:
XL2BB Add-in
Note that there is also a "
Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
-----
Example:
Dante Amor |
---|
|
---|
| A | B | C | D | E | F | G |
---|
1 | Time | SEQ | XTC | | Time | SEQ | XTC |
---|
2 | 10:12:05 | H | 0.5 | | 10:12:05 | H | 0.5 |
---|
3 | 10:12:06 | H | 0.5 | | 10:12:07 | H | 0 |
---|
4 | 10:12:07 | H | 0 | | 10:12:10 | H | 3 |
---|
5 | 10:12:08 | H | 0 | | 10:12:11 | S | 0.5 |
---|
6 | 10:12:09 | H | 1 | | 10:12:13 | S | 0 |
---|
7 | 10:12:10 | H | 3 | | 10:12:18 | S | 4 |
---|
8 | 10:12:11 | S | 0.5 | | 10:12:19 | H | 0.5 |
---|
9 | 10:12:12 | S | 0.5 | | 10:12:21 | H | 0 |
---|
10 | 10:12:13 | S | 0 | | 10:12:24 | H | 5 |
---|
11 | 10:12:14 | S | 0.5 | | 10:12:25 | S | 0.5 |
---|
12 | 10:12:15 | S | 1 | | 10:12:27 | S | 0 |
---|
13 | 10:12:16 | S | 1.5 | | 10:12:32 | S | 6 |
---|
14 | 10:12:17 | S | 1 | | 10:12:33 | H | 0 |
---|
15 | 10:12:18 | S | 4 | | 10:12:34 | H | 7 |
---|
16 | 10:12:19 | H | 0.5 | | | | |
---|
17 | 10:12:20 | H | 1 | | | | |
---|
18 | 10:12:21 | H | 0 | | | | |
---|
19 | 10:12:22 | H | 1.5 | | | | |
---|
20 | 10:12:23 | H | 0.5 | | | | |
---|
21 | 10:12:24 | H | 5 | | | | |
---|
22 | 10:12:25 | S | 0.5 | | | | |
---|
23 | 10:12:26 | S | 0.5 | | | | |
---|
24 | 10:12:27 | S | 0 | | | | |
---|
25 | 10:12:28 | S | 0.5 | | | | |
---|
26 | 10:12:29 | S | 1 | | | | |
---|
27 | 10:12:30 | S | 1.5 | | | | |
---|
28 | 10:12:31 | S | 0.5 | | | | |
---|
29 | 10:12:32 | S | 6 | | | | |
---|
30 | 10:12:33 | H | 0 | | | | |
---|
31 | 10:12:34 | H | 7 | | | | |
---|
|
---|