PC Review


Reply
Thread Tools Rate Thread

delete rows where value of cell "starts with" something

 
 
tahrah
Guest
Posts: n/a
 
      13th Jan 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2FyaSBKIEtlaW5vbmVu?=
Guest
Posts: n/a
 
      13th Jan 2007
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
 
Reply With Quote
 
=?Utf-8?B?S2FyaSBKIEtlaW5vbmVu?=
Guest
Posts: n/a
 
      13th Jan 2007
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

 
Reply With Quote
 
=?Utf-8?B?S2FyaSBKIEtlaW5vbmVu?=
Guest
Posts: n/a
 
      13th Jan 2007
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
 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      13th Jan 2007
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 (custom>Start with)


--

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


"tahrah" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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
>

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      13th Jan 2007
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
>
>

 
Reply With Quote
 
tahrah
Guest
Posts: n/a
 
      15th Jan 2007
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
> >
> >


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      15th Jan 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to delete all (and only) rows with cell value "" (blank) incolumn A Snoopy Microsoft Excel Discussion 1 11th Sep 2009 01:18 PM
delete rows if cell in row contains "a" or "o" or empty bartman1980 Microsoft Excel Programming 2 4th Nov 2007 08:20 PM
Look for cell containing "Initial" then if the next cell after equals "Final" then delete both rows. amorrison2006@googlemail.com Microsoft Excel Programming 3 28th Sep 2007 01:45 PM
Re: "Last Cell" to find last row, but can't delete blank rows Ron de Bruin Microsoft Excel Misc 0 8th Jan 2007 09:05 PM
Re: "Last Cell" to find last row, but can't delete blank rows Don Guillett Microsoft Excel Misc 0 8th Jan 2007 09:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:13 PM.