Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 10
Default Macro to delete row if cells greater than certain value

Dear all,

I've 1 column called Duration in my excel. I want to create a macro to check if duration is greater than 10 years, then delete the row. The duration is in range i.e 0-3, 5-10 and etc. I've created a macro but somehow it also delete rows with Duration less than 10 years. For this macro i formatted the Duration column as Text because if i set it to Number is will translate it into number i.e. 11-13 become 41579. Below I illustrate the scenario and my sample coding. Thanks in advance for any 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 Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Macro to delete row if cells greater than certain value

Hi,

Am Mon, 3 Dec 2012 04:43:00 +0000 schrieb ixara:

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


try:

Sub Test()
Dim LRow As Long
Dim i As Long
Dim intSearch As Integer

Application.ScreenUpdating = False
LRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = LRow To 2 Step -1
With Cells(i, 3)
intSearch = CInt(Left(.Text, InStr(.Text, "-") - 1))
If intSearch = 10 Then
Rows(i).Delete
End If
End With
Next
Application.ScreenUpdating = True
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a macro to delete cells from any row CYaYa Excel Programming 4 July 22nd 09 07:08 PM
Filter and Delete all rows with a date greater than or = today Tasha Excel Programming 0 February 5th 08 10:11 PM
macro to select cells containing specific text and delete all cells but these JenIT Excel Programming 3 March 27th 06 10:07 PM
Delete Rows with Value greater than X STEVEB Excel Programming 4 July 26th 05 09:08 PM
Macro if greater than letter then delete mike b Excel Programming 11 April 16th 05 01:39 PM


All times are GMT +1. The time now is 12:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"