PC Review


Reply
Thread Tools Rate Thread

How to Delete rows in a column

 
 
=?Utf-8?B?QUxBVEw=?=
Guest
Posts: n/a
 
      28th Nov 2006
I have the following data in Columns A and B. I would like to write code for
all rows in columns A and B that:

delete the rows for Example1 since the values in Column B are the same
delete the row for Example 2 since it only has one value
keep the rows for Example 3 since the values in Column B are NOT unique
delete the rows for Example 4 since the value in Column B are the same

Column A ColumnB
Example1 Create PO
Example1 Create PO
Example1 Create PO
Example2 Create PO
Example3 Approve Invoices
Example3 Approve Invoices
Example3 Create PO
Example4 Approve Invoices
Example4 Approve Invoices


Thanks!
 
Reply With Quote
 
 
 
 
Scott
Guest
Posts: n/a
 
      28th Nov 2006
One possible implementation would be to do as follows:

(It assumes that you've sorted by Column A)

1) Start at the last row, and find all the rows that have the same
value in Col A.

2) Iterate through each of those rows in Col B to determine if they
have only one type of value, or multiple types. (Do this by comparing
all values against the the value in Col B in the last row... if any are
different, you keep)

3) If any were different from step 2, delete all the rows that
correspond to that section.

4) Repeat 1-3, starting one row before the first row from the previous
section.

ie. For your example, last row is row 10. Rows 9-10 have the same
value in Col A. Go through values in Col B, find they are the same.
Delete rows 9-10. Repeat starting in row 8 (9 - 1).

Scott

ALATL wrote:
> I have the following data in Columns A and B. I would like to write code for
> all rows in columns A and B that:
>
> delete the rows for Example1 since the values in Column B are the same
> delete the row for Example 2 since it only has one value
> keep the rows for Example 3 since the values in Column B are NOT unique
> delete the rows for Example 4 since the value in Column B are the same
>
> Column A ColumnB
> Example1 Create PO
> Example1 Create PO
> Example1 Create PO
> Example2 Create PO
> Example3 Approve Invoices
> Example3 Approve Invoices
> Example3 Create PO
> Example4 Approve Invoices
> Example4 Approve Invoices
>
>
> Thanks!


 
Reply With Quote
 
Scott
Guest
Posts: n/a
 
      29th Nov 2006
Something like this:

Public Sub removal()
Dim z As Long
Dim y As Long
Dim i As Long
Dim t As String
Dim Same As Boolean
Dim WS As Worksheet

Set WS = Worksheets("Sheet1")
z = WS.Range("A65536").End(xlUp).Row

While z > 1
y = z
While WS.Cells(y - 1, 1) = WS.Cells(z, 1)
y = y - 1
Wend

Same = True
t = WS.Cells(z, 2)
For i = y To z
If WS.Cells(i, 2) <> t Then Same = False
Next i

If Same Then WS.Range(y & ":" & z).Delete

z = y - 1
Wend
End Sub

Scott

ALATL wrote:
> Hmmm..... Yes, I do see that this would be a good method for achieving this.
> Unfortunately... I am new to VBA and don't understand the syntax to achieve
> what you are proposing. :-(
>
> Any more help would surely be appreciated.
>
> Thx.
>
> "Scott" wrote:
>
> > One possible implementation would be to do as follows:
> >
> > (It assumes that you've sorted by Column A)
> >
> > 1) Start at the last row, and find all the rows that have the same
> > value in Col A.
> >
> > 2) Iterate through each of those rows in Col B to determine if they
> > have only one type of value, or multiple types. (Do this by comparing
> > all values against the the value in Col B in the last row... if any are
> > different, you keep)
> >
> > 3) If any were different from step 2, delete all the rows that
> > correspond to that section.
> >
> > 4) Repeat 1-3, starting one row before the first row from the previous
> > section.
> >
> > ie. For your example, last row is row 10. Rows 9-10 have the same
> > value in Col A. Go through values in Col B, find they are the same.
> > Delete rows 9-10. Repeat starting in row 8 (9 - 1).
> >
> > Scott
> >
> > ALATL wrote:
> > > I have the following data in Columns A and B. I would like to write code for
> > > all rows in columns A and B that:
> > >
> > > delete the rows for Example1 since the values in Column B are the same
> > > delete the row for Example 2 since it only has one value
> > > keep the rows for Example 3 since the values in Column B are NOT unique
> > > delete the rows for Example 4 since the value in Column B are the same
> > >
> > > Column A ColumnB
> > > Example1 Create PO
> > > Example1 Create PO
> > > Example1 Create PO
> > > Example2 Create PO
> > > Example3 Approve Invoices
> > > Example3 Approve Invoices
> > > Example3 Create PO
> > > Example4 Approve Invoices
> > > Example4 Approve Invoices
> > >
> > >
> > > 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
delete rows where value in Column B=0 sek0910 Microsoft Excel Programming 2 8th Feb 2008 08:52 PM
Delete Rows if any cell in Column H is blank but do not Delete Fir =?Utf-8?B?bWFuZmFyZWVk?= Microsoft Excel Programming 4 28th Sep 2007 05:20 PM
Delete Rows Where Value in Column V is Less than 2.5? =?Utf-8?B?U3RldmVD?= Microsoft Excel Programming 1 1st Feb 2006 09:18 PM
Delete rows with nothing in Column B marlea Microsoft Excel Programming 3 31st Jan 2006 03:39 PM
Delete All Rows That Column A value is not in Column A of Sheet2 paxdak@yahoo.com Microsoft Excel Programming 2 3rd Sep 2004 09:13 PM


Features
 

Advertising
 

Newsgroups
 


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