Data Formatting

  • Thread starter Programmer wanna be
  • Start date
P

Programmer wanna be

Hello All.

In excel, I need to keep the first row when it is followed by other
rows with the first two cells the same.

Therefore:

CELLA CELLB CELLC
21 COMPANY TEXT VARIES - keep
21 COMPANY TEXT VARIES - delete
22 COMPANY TEXT VARIES - keep
22 COMPANY TEXT VARIES - delete
22 COMPANY TEXT VARIES - delete
23 COMPANY TEXT VARIES - keep
23 COMPANY TEXT VARIES - delete
23 COMPANY TEXT VARIES - delete
23 COMPANY TEXT VARIES - delete

Make sense?? Please help me.
 
M

merjet

Sub DeleteRows()
Dim iRow As Integer
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
iRow = 1
Do
If ws.Cells(iRow + 1, "A") = ws.Cells(iRow, "A") _
And ws.Cells(iRow + 1, "B") = ws.Cells(iRow, "B") Then
ws.Rows(iRow + 1).Delete
Else
iRow = iRow + 1
End If
Loop Until ws.Cells(iRow + 1, "A") = ""
End Sub

HTH,
Merjet
 
F

Frank Stone

Set currentcell = Range("A1")
do while not isempty(currentCell)
Set nextcell = currentcell.Offset(1,0)
if currentcell.value = nextcell.value then
nextcell.entirerow.delete
Set nextcell = currentcell.offset(1,0)
else
set currentcell = nextcell
end if
loop
 
P

Programmer wanna be

Hello.

Using the information below, I am getting the following error "Set ws
= Sheets("Sheet1")". What does that mean?? How do I fix it?

Thank you for all of your help.
 
N

Norman Jones

Hi Programmer wanna be,

Perhaps you do not have a sheet named Sheet1.

Try replacing Sheet1 with the name of your sheet.
 
Top