Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Delete row if column A cell text length is not 11

I want to loop through the data in column A and if the text length of
the contents of the cell is not equal to 11 I want to delete the row.

Here's what I have that is not working (error is function not
compatible with object or something to that effect):

For i = Range("A:A").Rows.Count To 1 Step -1
If WorksheetFunction.Len(Range("A:A").Rows(i)) < 11 Then
Range("A:A").Rows(i).EntireRow.Delete
End If
Next i

Can someone point out what I'm doing wrong, or suggest a better
method?

Thanks




John Keith

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Delete row if column A cell text length is not 11

Hi John,
this should do the trick.
You dont need to invoke the worksheet function to return the length.
Also you where testing the length of the Row
"Len(Range("A:A").Rows(i)) < 11" when you should be testing the
length of the value of the cell.
I think this is where you were going wrong.
Let me know if you have a problem

Kind regards
Bernie

-----------------------------------------------------------------------


Public Sub DeleteTheRows()
Dim i As Double 'Cant use and integer because it cant hold the value
65536.

With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
For i = Worksheets(1).Range("A:A").Rows.Count To 1 Step -1
If Len(Range("A:A").Cells(i)) < 11 Then
Range("A:A").Cells(i).EntireRow.Delete
End If
Next i
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete row if column A cell text length is not 11


Dim LastRow as long
dim i As long
With activesheet
'just look at the rows that are used
lastrow = .cells(.rows.count,"A").end(xlup).row

For i = lastrow to 1 Step -1
If len(.cells(i,"A").value) < 11 then
.Rows(i).Delete
End If
Next i
End with



John Keith wrote:

I want to loop through the data in column A and if the text length of
the contents of the cell is not equal to 11 I want to delete the row.

Here's what I have that is not working (error is function not
compatible with object or something to that effect):

For i = Range("A:A").Rows.Count To 1 Step -1
If WorksheetFunction.Len(Range("A:A").Rows(i)) < 11 Then
Range("A:A").Rows(i).EntireRow.Delete
End If
Next i

Can someone point out what I'm doing wrong, or suggest a better
method?

Thanks



John Keith


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Delete row if column A cell text length is not 11

On Tue, 30 Sep 2008 07:53:26 -0500, Dave Peterson
wrote:


Dim LastRow as long
dim i As long
With activesheet
'just look at the rows that are used
lastrow = .cells(.rows.count,"A").end(xlup).row

For i = lastrow to 1 Step -1
If len(.cells(i,"A").value) < 11 then
.Rows(i).Delete
End If
Next i
End with



Dave,

Thank you for your solution. It has given me a key for another problem
I need to solve.


John Keith

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
Text to column fixed length Luci Excel Discussion (Misc queries) 6 November 27th 08 06:27 PM
Summing a column based on the length of text in a cell in anothercolumn [email protected] Excel Worksheet Functions 13 November 26th 08 05:42 PM
Code to set text length in cell Sandy Excel Programming 4 December 29th 05 02:52 PM
Search a Column by text length kb_63 Excel Worksheet Functions 2 May 6th 05 09:17 PM
The text length versus the cell size... shockley Excel Programming 2 September 14th 03 02:43 AM


All times are GMT +1. The time now is 02:12 PM.

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"