Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Macro to delete rows

I need a macro to search through a sheet of approximately 5,000 rows and
delete any row where the length of the string in column A is greater than 5.
I'm using Excel 2003. Can anyone help?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Macro to delete rows

This should work:


Sub delSixUp()
Dim lastRow As Long, i As Long
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lastRow To 2 Step -1
If Len(Trim(ActiveSheet.Cells(i, 1).Value)) 5 Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub




"Ken G" wrote in message
...
I need a macro to search through a sheet of approximately 5,000 rows and
delete any row where the length of the string in column A is greater than
5.
I'm using Excel 2003. Can anyone help?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Macro to delete rows

Try

Sub MyMacro()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Len(Range("A" & lngRow)) 5 Then Rows(lngRow).Delete
End If
Next
End Sub

--
Jacob


"Ken G" wrote:

I need a macro to search through a sheet of approximately 5,000 rows and
delete any row where the length of the string in column A is greater than 5.
I'm using Excel 2003. Can anyone help?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Macro to delete rows

Thanks Jacob. Perfect.

"Jacob Skaria" wrote:

Try

Sub MyMacro()
Dim lngRow As Long
For lngRow = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Len(Range("A" & lngRow)) 5 Then Rows(lngRow).Delete
End If
Next
End Sub

--
Jacob


"Ken G" wrote:

I need a macro to search through a sheet of approximately 5,000 rows and
delete any row where the length of the string in column A is greater than 5.
I'm using Excel 2003. Can anyone help?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Macro to delete rows

Thanks also. This works just as well as the previous suggestion.

Problem solved!

"JLGWhiz" wrote:

This should work:


Sub delSixUp()
Dim lastRow As Long, i As Long
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lastRow To 2 Step -1
If Len(Trim(ActiveSheet.Cells(i, 1).Value)) 5 Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub




"Ken G" wrote in message
...
I need a macro to search through a sheet of approximately 5,000 rows and
delete any row where the length of the string in column A is greater than
5.
I'm using Excel 2003. Can anyone help?



.

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
Help with macro to delete rows Trevor Williams Excel Programming 0 June 5th 09 12:32 PM
Macro to delete 2 rows every 500 rows [email protected] Excel Programming 3 February 3rd 08 01:52 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM
HOW TO: Delete Rows with a Macro Jase Excel Programming 0 September 11th 03 06:05 AM


All times are GMT +1. The time now is 11:44 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"