View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
p45cal[_33_] p45cal[_33_] is offline
external usenet poster
 
Posts: 1
Default How to copy all rows that contain a certain criteria to a new sheet?


I suspect this line will never be true:
If Left(MyCell.Text, 4) = "Annual subscriptions"
Try:
If Left(MyCell.Text, *20*) = "Annual subscriptions"

Peter;457205 Wrote:
Hello Simon

Your solution worked, thank you. I have now added a new worksheet
"Subs" and added the following code (based on yours):

Sub Subs()
Dim MyCell As Range
Dim Sh As Worksheet
For Each Sh In Sheets(Array("Cash", "Bank", "Stock")) 'add sheets as
needed
For Each MyCell In Sheets(Sh.Name).Range("G1:G" &
Sheets(Sh.Name).Range("D" & Rows.Count).End(xlUp).Row)
If Left(MyCell.Text, 4) = "Annual subscriptions" Then
MyCell.EntireRow.Copy Destination:=Sheets("Subs").Range("A" &
Rows.Count).End(xlUp).Offset(1, 0)
End If
Next MyCell
Next Sh
End Sub

It doesn't work! Any ideas?!

From a very VBA beginner

Regards

Peter



--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?userid=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=125534