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

Hello,
I have code that I hoped would iterate through a column and delete rows if
values did not begin with a 7.

For Each rngDBSingleCostElemCell In wksSheet.Range("C2:C" &
lCostElemItemLastRow)
If Left(rngDBSingleCostElemCell, 1) < 7 Then
rngDBSingleCostElemCell.Rows.Delete
End If
Next rngDBSingleCostElemCell

The values in column C are numbers stored as text.
For some reason rows with values like 16101, 16151 remain.
thanks for any help.
Jake
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,276
Default delete rows for values


Hi,
Highlight column C and apply text to columns

"Jake" wrote:

Hello,
I have code that I hoped would iterate through a column and delete rows if
values did not begin with a 7.

For Each rngDBSingleCostElemCell In wksSheet.Range("C2:C" &
lCostElemItemLastRow)
If Left(rngDBSingleCostElemCell, 1) < 7 Then
rngDBSingleCostElemCell.Rows.Delete
End If
Next rngDBSingleCostElemCell

The values in column C are numbers stored as text.
For some reason rows with values like 16101, 16151 remain.
thanks for any help.
Jake

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default delete rows for values


Doesn't that only work for cells formatted as General in which the number is
preceded with an apostrophe? I think cells formatted as Text will remain as
Text after doing what you suggested.

--
Rick (MVP - Excel)


"Eduardo" wrote in message
...
Hi,
Highlight column C and apply text to columns

"Jake" wrote:

Hello,
I have code that I hoped would iterate through a column and delete rows
if
values did not begin with a 7.

For Each rngDBSingleCostElemCell In wksSheet.Range("C2:C" &
lCostElemItemLastRow)
If Left(rngDBSingleCostElemCell, 1) < 7 Then
rngDBSingleCostElemCell.Rows.Delete
End If
Next rngDBSingleCostElemCell

The values in column C are numbers stored as text.
For some reason rows with values like 16101, 16151 remain.
thanks for any help.
Jake


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default delete rows for values


I think you are falling victim to the removals that are taking place. When
you delete Row 1, all the other rows move up so that what was Row 2 is not
Row 1, etc. If Row2 had 16101 in it, that value would be in Row 1 after the
original Row 1 was deleted; but the For..Next loop already processed Row 1,
so it will not go back to it again. The way most people avoid this problem
is to iterate the loop row-by-row from the last row with data backwards to
the first row; that way, deletions do not affect the loop's processing
order. Try this (off the top of my head)...

With wksSheet
For X = lCostElemItemLastRow To 2 Step -1
If Left(.Cells(X, 1).Value, 1) < 7 Then .Cells(X, 1).EntireRow.Delete
Next
End With

--
Rick (MVP - Excel)


"Jake" wrote in message
...
Hello,
I have code that I hoped would iterate through a column and delete rows if
values did not begin with a 7.

For Each rngDBSingleCostElemCell In wksSheet.Range("C2:C" &
lCostElemItemLastRow)
If Left(rngDBSingleCostElemCell, 1) < 7 Then
rngDBSingleCostElemCell.Rows.Delete
End If
Next rngDBSingleCostElemCell

The values in column C are numbers stored as text.
For some reason rows with values like 16101, 16151 remain.
thanks for any help.
Jake


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default delete rows for values


Thanks Rick! Workin' great now.

"Rick Rothstein" wrote:

I think you are falling victim to the removals that are taking place. When
you delete Row 1, all the other rows move up so that what was Row 2 is not
Row 1, etc. If Row2 had 16101 in it, that value would be in Row 1 after the
original Row 1 was deleted; but the For..Next loop already processed Row 1,
so it will not go back to it again. The way most people avoid this problem
is to iterate the loop row-by-row from the last row with data backwards to
the first row; that way, deletions do not affect the loop's processing
order. Try this (off the top of my head)...

With wksSheet
For X = lCostElemItemLastRow To 2 Step -1
If Left(.Cells(X, 1).Value, 1) < 7 Then .Cells(X, 1).EntireRow.Delete
Next
End With

--
Rick (MVP - Excel)


"Jake" wrote in message
...
Hello,
I have code that I hoped would iterate through a column and delete rows if
values did not begin with a 7.

For Each rngDBSingleCostElemCell In wksSheet.Range("C2:C" &
lCostElemItemLastRow)
If Left(rngDBSingleCostElemCell, 1) < 7 Then
rngDBSingleCostElemCell.Rows.Delete
End If
Next rngDBSingleCostElemCell

The values in column C are numbers stored as text.
For some reason rows with values like 16101, 16151 remain.
thanks for any help.
Jake



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
Delete rows with duplicated values Emece Excel Discussion (Misc queries) 2 April 16th 09 12:52 PM
How to Delete empty rows in excel in b/w rows with values Dennis Excel Worksheet Functions 3 August 28th 07 04:15 PM
delete rows with 0 values andresg1975 Excel Programming 1 September 29th 06 03:49 PM
Delete Rows where there are #N/A Values FIRSTROUNDKO via OfficeKB.com Excel Worksheet Functions 3 August 3rd 06 04:03 PM
Delete rows with numeric values, leave rows with text GSpline Excel Programming 5 October 11th 05 12:44 AM


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