Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default delete rows where value of cell "starts with" something

How would I delete all rows where the value of a cell "starts with"
something. For example, if I have product numbers like 01-31-030,
01-30-132, 01-30-265 etc... and I want to delete all rows that "start
with" 01-30, how would I do that?

Then, if I want to copy ALL remaining rows/columns to a new
spreadsheet, how would I do that?

I appreciate your help.

Regards,
Tahrah

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default delete rows where value of cell "starts with" something

Hi Tahrah!

Try this one delete rows, I think it works.

Sub DeleteRows()
Dim selectRow As Long
Dim selectRange As Range
On Error GoTo TheEnd

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set selectRange = ActiveSheet.UsedRange.Rows

For selectRow = selectRange.Rows.Count To 1 Step -1
Cells.Find(What:="01-13-", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows).Activate
selectRange.Rows(selectRow).EntireRow.Delete
Next selectRow
TheEnd:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

Regards,
Kari J Keinonen
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default delete rows where value of cell "starts with" something

I'm sorry, it's not work.

"Kari J Keinonen" wrote:

Hi Tahrah!

Try this one delete rows, I think it works.

Sub DeleteRows()
Dim selectRow As Long
Dim selectRange As Range
On Error GoTo TheEnd

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set selectRange = ActiveSheet.UsedRange.Rows

For selectRow = selectRange.Rows.Count To 1 Step -1
Cells.Find(What:="01-13-", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows).Activate
selectRange.Rows(selectRow).EntireRow.Delete
Next selectRow
TheEnd:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

Regards,
Kari J Keinonen

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default delete rows where value of cell "starts with" something

Here you are a little bit better version, sorry.

Public Sub DeleteRows()
Dim selectRow As Long
Dim selectRange As Range
On Error GoTo TheEnd

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set selectRange = ActiveSheet.UsedRange.Rows

For selectRow = selectRange.Rows.Count To 1 Step -1
Cells.Find(What:="01-30-", After:=ActiveCell, LookIn:=xlValues,
LookAt _
:=xlPart, SearchOrder:=xlByRows).Activate
ActiveCell.EntireRow.Delete
Next selectRow
TheEnd:
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

Regards,
Kari J Keinonen
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default delete rows where value of cell "starts with" something

Hi tahrah

Install EasyFilter for this (also a option to copy to new sheet)
http://www.rondebruin.nl/easyfilter.htm

Or do a manual autofilter (customStart with)


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"tahrah" wrote in message ups.com...
How would I delete all rows where the value of a cell "starts with"
something. For example, if I have product numbers like 01-31-030,
01-30-132, 01-30-265 etc... and I want to delete all rows that "start
with" 01-30, how would I do that?

Then, if I want to copy ALL remaining rows/columns to a new
spreadsheet, how would I do that?

I appreciate your help.

Regards,
Tahrah



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default delete rows where value of cell "starts with" something

I used Worksheets(1) and Worksheets(2) and assumed that the product numbers
are in column A. Try this on a copy of your worksheet before you install it
for permanent use.

Sub deleRwCpy()
Dim myRng As Range
lr = Cells(Rows.Count, 1).End(xlUp).Row
lc = Cells(1, Columns.Count).End(xlToLeft).Column
Set myRng = Range("A1:A" & lr)
Do
Range("$A$1").Activate
Do
If Left(ActiveCell.Value, 5) < "01-31" Then
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.EntireRow.Delete
End If
Loop Until ActiveCell.Row = lr
Loop Until ActiveCell.Row = lr
Range(Cells(1, 1), Cells(lr, lc)).Copy
Destination:=Worksheets(2).Range("$A$1")
End Sub


"tahrah" wrote:

How would I delete all rows where the value of a cell "starts with"
something. For example, if I have product numbers like 01-31-030,
01-30-132, 01-30-265 etc... and I want to delete all rows that "start
with" 01-30, how would I do that?

Then, if I want to copy ALL remaining rows/columns to a new
spreadsheet, how would I do that?

I appreciate your help.

Regards,
Tahrah


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default delete rows where value of cell "starts with" something

JLGWhiz, It's giving a compile error and this line is red on the
macro:
Destination:=Worksheets(2).Range("$A$1")

Any ideas?

Regards,
Tahrah


JLGWhiz wrote:
I used Worksheets(1) and Worksheets(2) and assumed that the product numbers
are in column A. Try this on a copy of your worksheet before you install it
for permanent use.

Sub deleRwCpy()
Dim myRng As Range
lr = Cells(Rows.Count, 1).End(xlUp).Row
lc = Cells(1, Columns.Count).End(xlToLeft).Column
Set myRng = Range("A1:A" & lr)
Do
Range("$A$1").Activate
Do
If Left(ActiveCell.Value, 5) < "01-31" Then
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.EntireRow.Delete
End If
Loop Until ActiveCell.Row = lr
Loop Until ActiveCell.Row = lr
Range(Cells(1, 1), Cells(lr, lc)).Copy
Destination:=Worksheets(2).Range("$A$1")
End Sub


"tahrah" wrote:

How would I delete all rows where the value of a cell "starts with"
something. For example, if I have product numbers like 01-31-030,
01-30-132, 01-30-265 etc... and I want to delete all rows that "start
with" 01-30, how would I do that?

Then, if I want to copy ALL remaining rows/columns to a new
spreadsheet, how would I do that?

I appreciate your help.

Regards,
Tahrah



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default delete rows where value of cell "starts with" something

You got hit by line wrap...

This is one logical line:

Range(Cells(1, 1), Cells(lr, lc)).Copy _
Destination:=Worksheets(2).Range("$A$1")

(Added an underscore followed by a space after the .copy)

tahrah wrote:

JLGWhiz, It's giving a compile error and this line is red on the
macro:
Destination:=Worksheets(2).Range("$A$1")

Any ideas?

Regards,
Tahrah

JLGWhiz wrote:
I used Worksheets(1) and Worksheets(2) and assumed that the product numbers
are in column A. Try this on a copy of your worksheet before you install it
for permanent use.

Sub deleRwCpy()
Dim myRng As Range
lr = Cells(Rows.Count, 1).End(xlUp).Row
lc = Cells(1, Columns.Count).End(xlToLeft).Column
Set myRng = Range("A1:A" & lr)
Do
Range("$A$1").Activate
Do
If Left(ActiveCell.Value, 5) < "01-31" Then
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.EntireRow.Delete
End If
Loop Until ActiveCell.Row = lr
Loop Until ActiveCell.Row = lr
Range(Cells(1, 1), Cells(lr, lc)).Copy
Destination:=Worksheets(2).Range("$A$1")
End Sub


"tahrah" wrote:

How would I delete all rows where the value of a cell "starts with"
something. For example, if I have product numbers like 01-31-030,
01-30-132, 01-30-265 etc... and I want to delete all rows that "start
with" 01-30, how would I do that?

Then, if I want to copy ALL remaining rows/columns to a new
spreadsheet, how would I do that?

I appreciate your help.

Regards,
Tahrah



--

Dave Peterson
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
How to delete rows with "-" in cell RS Excel Discussion (Misc queries) 0 February 17th 10 04:27 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
"Last Cell" to find last row, but can't delete blank rows [email protected] Excel Discussion (Misc queries) 6 January 8th 07 11:50 PM
Delete rows that cell value is "No" Tim Excel Programming 4 June 17th 06 10:13 AM
How do I get "file" tab to click on, it starts with "edit" JMD_Phoenix Excel Discussion (Misc queries) 1 January 23rd 06 02:46 AM


All times are GMT +1. The time now is 02:13 AM.

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

About Us

"It's about Microsoft Excel"