Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Help Delete Rows based on the macro in this message

Hi

Could someone please help me with the following macro? The macro sorts two columns of data so that identical information lines up side by side. My problem is, I would like anything that matches in column A & B to be deleted only leaving the data where there is not another matching record in the column next to it.

I would also like any rows that have been deleted to shift up so I am only left with rows with data in them and no blank rows.

Please see the code below.

Sub Macro()
Dim myCell As Range
Dim row As Long, i As Long

Range("A:A").Sort Key1:=Range("A1"), order1:=xlAscending, header:=xlNo
Range("B:B").Sort Key1:=Range("B1"), order1:=xlAscending, header:=xlNo

row = 1
Do Until IsEmpty(Cells(row, "A")) And IsEmpty(Cells(row, "B"))

If Cells(row, 2).Value < Cells(row, 1).Value And Cells(row, 1).Value < Cells(row, 2).Value Then
Cells(row, 2).Insert Shift:=xlDown
Else
If Cells(row, 1).Value < Cells(row, 2).Value And Cells(row, 2).Value Cells(row, 1).Value Then
Cells(row, 2).Insert Shift:=xlDown
End If
End If
row = row + 1
Loop
End Sub


Thanks in advance

Malcolm


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Help Delete Rows based on the macro in this message

Your code and message is confusing because you talk about deleting rows and
your code inserts them. anyway this is how I might generally delete any
rows where the values in columns A and B are the same:

Sub a()
Dim Counter As Long
Dim LastRow As Long
LastRow = Range("A65536").End(xlUp).Row
For Counter = LastRow To 1 Step -1
If Cells(Counter, 1).Value = Cells(Counter, 2).Value Then _
Rows(Counter).Delete xlUp
Next
End Sub

--
Jim Rech
Excel MVP
"malycom" wrote in message
...
| Hi
|
| Could someone please help me with the following macro? The macro sorts
two columns of data so that identical information lines up side by side. My
problem is, I would like anything that matches in column A & B to be deleted
only leaving the data where there is not another matching record in the
column next to it.
|
| I would also like any rows that have been deleted to shift up so I am only
left with rows with data in them and no blank rows.
|
| Please see the code below.
|
| Sub Macro()
| Dim myCell As Range
| Dim row As Long, i As Long
|
| Range("A:A").Sort Key1:=Range("A1"), order1:=xlAscending, header:=xlNo
| Range("B:B").Sort Key1:=Range("B1"), order1:=xlAscending, header:=xlNo
|
| row = 1
| Do Until IsEmpty(Cells(row, "A")) And IsEmpty(Cells(row, "B"))
|
| If Cells(row, 2).Value < Cells(row, 1).Value And Cells(row, 1).Value <
Cells(row, 2).Value Then
| Cells(row, 2).Insert Shift:=xlDown
| Else
| If Cells(row, 1).Value < Cells(row, 2).Value And Cells(row, 2).Value
Cells(row, 1).Value Then
| Cells(row, 2).Insert Shift:=xlDown
| End If
| End If
| row = row + 1
| Loop
| End Sub
|
|
| Thanks in advance
|
| Malcolm
|
|


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
Delete Rows based on condition Vic Excel Discussion (Misc queries) 2 August 18th 09 08:54 PM
Macro to delete rows based on date PMBO Excel Discussion (Misc queries) 4 February 18th 09 01:50 PM
Delete Rows based on value Sabosis Excel Worksheet Functions 4 October 28th 08 11:21 PM
Macro to delete rows based on a condition Darrilyn Excel Worksheet Functions 1 September 6th 07 12:12 AM
Cut and Paste macro based on criteria then delete empty rows samst Excel Programming 4 November 2nd 03 09:33 PM


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

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"