Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro or VBA

I hane a column in a spread sheet whose values at times are repeats of the cell above. I want that row deleted if the value is the same as the cell above is there a way to do it programaticallY?

e.g.
A B C D E
Acct # MedRec# field field field
112233 xxx xxx xxx xxx
112233 xxx xxx xxx xxx
123123 xxx xxx xxx xxx
123412 xxx xxx xxx xxx
123412 xxx xxx xxx xxx

I would want the rows in bold red deleted

--
Gail M Horvath



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro or VBA

Gail,

How about:

Sub DeleteDupRows()
With ActiveSheet
For iRow = 100 To 2 Step -1 'change 100 to last row
If Cells(iRow, 1) = Cells(iRow - 1, 1) Then
Cells(iRow, 1).EntireRow.Delete
End If
Next iRow
End With
End Sub

Don Pistulka


"GAIL HORVATH" wrote in message ...
I hane a column in a spread sheet whose values at times are repeats of the cell above. I want that row deleted if the value is the same as the cell above is there a way to do it programaticallY?

e.g.
A B C D E
Acct # MedRec# field field field
112233 xxx xxx xxx xxx
112233 xxx xxx xxx xxx
123123 xxx xxx xxx xxx
123412 xxx xxx xxx xxx
123412 xxx xxx xxx xxx

I would want the rows in bold red deleted

--
Gail M Horvath



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Macro or VBA

Try this. Please advise if it works or not.

Regards,
Greg

Sub DeleteDuplicates()
Dim i As Long, x As Long, rw As Long
Dim rng As Range

Set rng = Selection
rw = Selection.Row + Selection.Count - 1
i = 2: x = 0
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
Do Until x = rw
If Cells(i, 1).Value = Cells(i - 1, 1).Value Then
Cells(i, 1).EntireRow.Delete
Else
i = i + 1
End If
x = x + 1
Loop
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub

"GAIL HORVATH" wrote:

I hane a column in a spread sheet whose values at times are repeats of the cell above. I want that row deleted if the value is the same as the cell above is there a way to do it programaticallY?

e.g.
A B C D E
Acct # MedRec# field field field
112233 xxx xxx xxx xxx
112233 xxx xxx xxx xxx
123123 xxx xxx xxx xxx
123412 xxx xxx xxx xxx
123412 xxx xxx xxx xxx

I would want the rows in bold red deleted

--
Gail M Horvath

x

  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Macro or VBA

Correction to my post:-

Change the line:
i = 2: x = 0
To:
i = Selection.Row: x = Selection.Row - 1

Regards,
Greg
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro or VBA

It worked once now I get error code 400

--
Gail M Horvath


Eastern Time Zone
"Greg Wilson" wrote in message
...
Correction to my post:-

Change the line:
i = 2: x = 0
To:
i = Selection.Row: x = Selection.Row - 1

Regards,
Greg



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Macro or VBA

I made a slight correction. When I did my trials, the selected range was not
at the top of the column. Therefore, the line "Selection.Row - 1" did not
raise an error because it just referenced 1 cell above the selection.
However, if you select to the top of the column this line attempts to
reference above row 1, i.e. beyond the worksheet, and thus raises an error.
(I get error 1004 however?)

Try this instead:
Sub DeleteDuplicates()
Dim i As Long, x As Long, rw As Long
Dim rng As Range

Set rng = Selection
rw = Selection.Row + Selection.Count - 1
i = Selection.Row + 1: x = Selection.Row
With Application
..ScreenUpdating = False
..Calculation = xlCalculationManual
Do Until x = rw
If Cells(i, 1).Value = Cells(i - 1, 1).Value Then
Cells(i, 1).EntireRow.Delete
Else
i = i + 1
End If
x = x + 1
Loop
..Calculation = xlCalculationAutomatic
..ScreenUpdating = True
End With
End Sub

Regards,
Greg

"GAIL HORVATH" wrote:

It worked once now I get error code 400

--
Gail M Horvath


Eastern Time Zone
"Greg Wilson" wrote in message
...
Correction to my post:-

Change the line:
i = 2: x = 0
To:
i = Selection.Row: x = Selection.Row - 1

Regards,
Greg




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro or VBA

Don's code performs the same equality test as Greg's and is much simpler by
looping in reverse and requiring no selection. Think you wasted your time
not adequately testing it. I ran it on the data you posted and it did
exactly what you asked.

--
Regards,
Tom Ogilvy


"GAIL HORVATH" wrote in message
...
Doesn't work. I probably wasn't clear in what I needed. This is a better
example It is whwn A2=A3 etc that I want the entire row deleted
e.g.
A B C D E
Acct # MedRec# field field field
112233 xxx xxx xxx xxx
112233 xxx xxx xxx yyy
123123 xxx xxx xxx xxx
123412 xxx xxx xxx xxx
123412 xxx xxx xxx ttt
123412 xxx xxx xxx sss
--
Gail M Horvath


Eastern Time Zone
"Don" wrote in message
...
Gail,

How about:

Sub DeleteDupRows()
With ActiveSheet
For iRow = 100 To 2 Step -1 'change 100 to last row
If Cells(iRow, 1) = Cells(iRow - 1, 1) Then
Cells(iRow, 1).EntireRow.Delete
End If
Next iRow
End With
End Sub

Don Pistulka


"GAIL HORVATH" wrote in message
...
I hane a column in a spread sheet whose values at times are repeats of
the cell above. I want that row deleted if the value is the same as the cell
above is there a way to do it programaticallY?

e.g.
A B C D E
Acct # MedRec# field field field
112233 xxx xxx xxx xxx
112233 xxx xxx xxx yyy
123123 xxx xxx xxx xxx
123412 xxx xxx xxx xxx
123412 xxx xxx xxx ttt
123412 xxx xxx xxx sss

I would want the rows in bold red deleted

--
Gail M Horvath




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
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Excel Programming 1 October 15th 04 01:16 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 02:55 AM.

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"