I
ixara
Dear all,
I've 1 column called Duration in my excel. I want to create a macro t
check if duration is greater than 10 years, then delete the row. Th
duration is in range i.e 0-3, 5-10 and etc. I've created a macro bu
somehow it also delete rows with Duration less than 10 years. For thi
macro i formatted the Duration column as Text because if i set it t
Number is will translate it into number i.e. 11-13 become 41579. Below
illustrate the scenario and my sample coding. Thanks in advance for an
help.
Original data
------------
ColA ColB ColC
Item Code Duration
1 DE123 0-3
2 PK987 7-10
3 BG313 10-13
4 JJ123 5-7
5 AW100 12-15
Expected result
---------------
ColA ColB ColC
Item Code Duration
1 DE123 0-3
2 PK987 7-10
4 JJ123 5-7
Sample code
------------
Sub ExceedDuration()
Dim lr As Long
Dim R As Integer
Dim n As Integer
Application.ScreenUpdating = False
Set TestBook = ActiveWorkbook
Windows("Test.xls").Activate
Sheets("Sheet1").Select
Range("A2").Select
lr = Cells(Rows.Count, 1).End(xlUp).Row
n = 1
For R = 3 To lr
Sheets("Sheet1").Select
Range("A3").Select
FindString = Range("C" & R).Value
If (Range("C" & R).Value) > "10" Then
Range("A" & R & ":C" & R).delete
n = n + 1
End If
Next R
End Su
I've 1 column called Duration in my excel. I want to create a macro t
check if duration is greater than 10 years, then delete the row. Th
duration is in range i.e 0-3, 5-10 and etc. I've created a macro bu
somehow it also delete rows with Duration less than 10 years. For thi
macro i formatted the Duration column as Text because if i set it t
Number is will translate it into number i.e. 11-13 become 41579. Below
illustrate the scenario and my sample coding. Thanks in advance for an
help.
Original data
------------
ColA ColB ColC
Item Code Duration
1 DE123 0-3
2 PK987 7-10
3 BG313 10-13
4 JJ123 5-7
5 AW100 12-15
Expected result
---------------
ColA ColB ColC
Item Code Duration
1 DE123 0-3
2 PK987 7-10
4 JJ123 5-7
Sample code
------------
Sub ExceedDuration()
Dim lr As Long
Dim R As Integer
Dim n As Integer
Application.ScreenUpdating = False
Set TestBook = ActiveWorkbook
Windows("Test.xls").Activate
Sheets("Sheet1").Select
Range("A2").Select
lr = Cells(Rows.Count, 1).End(xlUp).Row
n = 1
For R = 3 To lr
Sheets("Sheet1").Select
Range("A3").Select
FindString = Range("C" & R).Value
If (Range("C" & R).Value) > "10" Then
Range("A" & R & ":C" & R).delete
n = n + 1
End If
Next R
End Su