PC Review


Reply
Thread Tools Rate Thread

Delete rows containing Vendor Total A,B,C etc

 
 
=?Utf-8?B?aWFuc21pZ2dlcg==?=
Guest
Posts: n/a
 
      5th Jul 2007
Hi

I am looking for a macro that will delete entire rows from a report
containing the phrase 'Vendor Total' followed by Company name.

Here is an example of the raw data:-

Company Apple
Vendor Total Company Apple
Vendor Total Company Banana
Vendor Total Company Banana
Company Orange
Company Apple
Vendor Total Comapany Pear

Once the macro has run and deleted out the entire lines containg Vendor
Total, the following data should remain:-

Company Apple
Company Orange
Company Apple

There is a header in row 1 that should remain.

Thanks
 
Reply With Quote
 
 
 
 
=?Utf-8?B?UHJhbmF2IFZhaWR5YQ==?=
Guest
Posts: n/a
 
      5th Jul 2007
try the below code

Worksheets("Sheet2").Activate
Dim i As Integer
Dim LastRow As Long
LastRow = Range("A65000").End(xlUp).Row
For i = 2 To LastRow
If InStr(1, Range("A" & i).Value, "Vendor Total") Then Rows(i).Delete
Next

"iansmigger" wrote:

> Hi
>
> I am looking for a macro that will delete entire rows from a report
> containing the phrase 'Vendor Total' followed by Company name.
>
> Here is an example of the raw data:-
>
> Company Apple
> Vendor Total Company Apple
> Vendor Total Company Banana
> Vendor Total Company Banana
> Company Orange
> Company Apple
> Vendor Total Comapany Pear
>
> Once the macro has run and deleted out the entire lines containg Vendor
> Total, the following data should remain:-
>
> Company Apple
> Company Orange
> Company Apple
>
> There is a header in row 1 that should remain.
>
> Thanks

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      5th Jul 2007
Sub deleterows()

RowCount = 2
Do While Not IsEmpty(Cells(RowCount, "A"))

Set myrow = Range("A" & RowCount).EntireRow
Set c = myrow.Find("Vendor Total", LookIn:=xlValues)
If Not c Is Nothing Then
c.EntireRow.Delete
Else
RowCount = RowCount + 1
End If
Loop


End Sub


"iansmigger" wrote:

> Hi
>
> I am looking for a macro that will delete entire rows from a report
> containing the phrase 'Vendor Total' followed by Company name.
>
> Here is an example of the raw data:-
>
> Company Apple
> Vendor Total Company Apple
> Vendor Total Company Banana
> Vendor Total Company Banana
> Company Orange
> Company Apple
> Vendor Total Comapany Pear
>
> Once the macro has run and deleted out the entire lines containg Vendor
> Total, the following data should remain:-
>
> Company Apple
> Company Orange
> Company Apple
>
> There is a header in row 1 that should remain.
>
> Thanks

 
Reply With Quote
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      5th Jul 2007
Your for loop will not work. Not all the rows will get deleted especialy is
the Vendor Total is on consecutive lines.

row 5 Vendor Total Company Apple <= will get deleted
row 6 Vendor Total Company Banana <= gets skipped
row 7 Vendor Total Company Banana <= will get deleted

"Pranav Vaidya" wrote:

> try the below code
>
> Worksheets("Sheet2").Activate
> Dim i As Integer
> Dim LastRow As Long
> LastRow = Range("A65000").End(xlUp).Row
> For i = 2 To LastRow
> If InStr(1, Range("A" & i).Value, "Vendor Total") Then Rows(i).Delete
> Next
>
> "iansmigger" wrote:
>
> > Hi
> >
> > I am looking for a macro that will delete entire rows from a report
> > containing the phrase 'Vendor Total' followed by Company name.
> >
> > Here is an example of the raw data:-
> >
> > Company Apple
> > Vendor Total Company Apple
> > Vendor Total Company Banana
> > Vendor Total Company Banana
> > Company Orange
> > Company Apple
> > Vendor Total Comapany Pear
> >
> > Once the macro has run and deleted out the entire lines containg Vendor
> > Total, the following data should remain:-
> >
> > Company Apple
> > Company Orange
> > Company Apple
> >
> > There is a header in row 1 that should remain.
> >
> > Thanks

 
Reply With Quote
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      5th Jul 2007
I think your may need to run this loop backwards to make it work step -1

"Pranav Vaidya" wrote:

> try the below code
>
> Worksheets("Sheet2").Activate
> Dim i As Integer
> Dim LastRow As Long
> LastRow = Range("A65000").End(xlUp).Row
> For i = 2 To LastRow
> If InStr(1, Range("A" & i).Value, "Vendor Total") Then Rows(i).Delete
> Next
>
> "iansmigger" wrote:
>
> > Hi
> >
> > I am looking for a macro that will delete entire rows from a report
> > containing the phrase 'Vendor Total' followed by Company name.
> >
> > Here is an example of the raw data:-
> >
> > Company Apple
> > Vendor Total Company Apple
> > Vendor Total Company Banana
> > Vendor Total Company Banana
> > Company Orange
> > Company Apple
> > Vendor Total Comapany Pear
> >
> > Once the macro has run and deleted out the entire lines containg Vendor
> > Total, the following data should remain:-
> >
> > Company Apple
> > Company Orange
> > Company Apple
> >
> > There is a header in row 1 that should remain.
> >
> > Thanks

 
Reply With Quote
 
=?Utf-8?B?aWFuc21pZ2dlcg==?=
Guest
Posts: n/a
 
      5th Jul 2007
Thant works a treat!

Thanks

"Joel" wrote:

> Sub deleterows()
>
> RowCount = 2
> Do While Not IsEmpty(Cells(RowCount, "A"))
>
> Set myrow = Range("A" & RowCount).EntireRow
> Set c = myrow.Find("Vendor Total", LookIn:=xlValues)
> If Not c Is Nothing Then
> c.EntireRow.Delete
> Else
> RowCount = RowCount + 1
> End If
> Loop
>
>
> End Sub
>
>
> "iansmigger" wrote:
>
> > Hi
> >
> > I am looking for a macro that will delete entire rows from a report
> > containing the phrase 'Vendor Total' followed by Company name.
> >
> > Here is an example of the raw data:-
> >
> > Company Apple
> > Vendor Total Company Apple
> > Vendor Total Company Banana
> > Vendor Total Company Banana
> > Company Orange
> > Company Apple
> > Vendor Total Comapany Pear
> >
> > Once the macro has run and deleted out the entire lines containg Vendor
> > Total, the following data should remain:-
> >
> > Company Apple
> > Company Orange
> > Company Apple
> >
> > There is a header in row 1 that should remain.
> >
> > Thanks

 
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
Format Total but not GRAND Total rows MikeF Microsoft Excel Programming 0 29th Dec 2008 11:04 PM
Drop-Down Select Vendor to Populate Vendor Form =?Utf-8?B?ZGgxMDY5?= Microsoft Access Forms 9 4th May 2007 09:18 AM
Korean AV vendor AhnLab now a part of Virus Total David H. Lipman Anti-Virus 3 17th Mar 2007 12:06 AM
Delete Rows that Contain the Text "Total" and vice versa =?Utf-8?B?U3RldmVD?= Microsoft Excel Programming 7 25th Jan 2006 07:11 PM
Search "Total" in all worksheets and delete rows containing "Total" mk_garg20 Microsoft Excel Programming 2 30th Jul 2004 06:42 AM


Features
 

Advertising
 

Newsgroups
 


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