#1   Report Post  
Posted to microsoft.public.excel.misc
Tom Tom is offline
external usenet poster
 
Posts: 17
Default Help with codes

Hi,

My macro first sorts Column A which contains a string of text
alphabetically. It then compares the text down each consecutive row and
prints, "Repeated Entry" in Column B next to it if they are found. It then
sorts Column A:B alphabetically along Column B. At this point and to do a
repetition, For N = 1 to 100 is used. It then searches for the words
"Repeated Entry" and deletes that row. Then comes, Next N. Here is where I
need some help. If there are less than 100 "Repeated Entry" lines, I get the
message,
"Run time error '91': Object variable or With block variable not set". The
macro execution then stops. How can I error trap this so as to allow the
execution to continue on?

TIA
Tom


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Help with codes

Use this type loop. Notice Rowcount doesn't get incremented when you delete
a row.

RowCount = 1
Do while cells(RowCount,"A") < ""
if cells(RowCount,"B") = "Repeated Entry" then
Rows(RowCount).delete
else
RowCount = RowCount + 1
loop

"Tom" wrote:

Hi,

My macro first sorts Column A which contains a string of text
alphabetically. It then compares the text down each consecutive row and
prints, "Repeated Entry" in Column B next to it if they are found. It then
sorts Column A:B alphabetically along Column B. At this point and to do a
repetition, For N = 1 to 100 is used. It then searches for the words
"Repeated Entry" and deletes that row. Then comes, Next N. Here is where I
need some help. If there are less than 100 "Repeated Entry" lines, I get the
message,
"Run time error '91': Object variable or With block variable not set". The
macro execution then stops. How can I error trap this so as to allow the
execution to continue on?

TIA
Tom



  #3   Report Post  
Posted to microsoft.public.excel.misc
Tom Tom is offline
external usenet poster
 
Posts: 17
Default Help with codes

That last word "loop". Where should I put it for it to work properly?
Thanks!

"Joel" wrote in message
...
Use this type loop. Notice Rowcount doesn't get incremented when you
delete
a row.

RowCount = 1
Do while cells(RowCount,"A") < ""
if cells(RowCount,"B") = "Repeated Entry" then
Rows(RowCount).delete
else
RowCount = RowCount + 1
loop

"Tom" wrote:

Hi,

My macro first sorts Column A which contains a string of text
alphabetically. It then compares the text down each consecutive row and
prints, "Repeated Entry" in Column B next to it if they are found. It
then
sorts Column A:B alphabetically along Column B. At this point and to do a
repetition, For N = 1 to 100 is used. It then searches for the words
"Repeated Entry" and deletes that row. Then comes, Next N. Here is where
I
need some help. If there are less than 100 "Repeated Entry" lines, I get
the
message,
"Run time error '91': Object variable or With block variable not set".
The
macro execution then stops. How can I error trap this so as to allow the
execution to continue on?

TIA
Tom





  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Help with codes

You're code will be much simpler if you work from the bottom toward the top.

Option Explicit
Sub testme01()

Dim LastRow As Long
Dim FirstRow As Long
Dim iRow As Long

With Worksheets("sheet1")
FirstRow = 1
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For iRow = LastRow To FirstRow Step -1
If LCase(.Cells(iRow, "B").Value) = LCase("repeated entry") Then
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

Instead of using 1 to N, I used 1 to the last row that was used in column B.

I could have used:

FirstRow = 1
LastRow = 100



Tom wrote:

Hi,

My macro first sorts Column A which contains a string of text
alphabetically. It then compares the text down each consecutive row and
prints, "Repeated Entry" in Column B next to it if they are found. It then
sorts Column A:B alphabetically along Column B. At this point and to do a
repetition, For N = 1 to 100 is used. It then searches for the words
"Repeated Entry" and deletes that row. Then comes, Next N. Here is where I
need some help. If there are less than 100 "Repeated Entry" lines, I get the
message,
"Run time error '91': Object variable or With block variable not set". The
macro execution then stops. How can I error trap this so as to allow the
execution to continue on?

TIA
Tom


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
Tom Tom is offline
external usenet poster
 
Posts: 17
Default Help with codes

My sincere thanks to you both, Joel and Dave. Your suggestions are much
appreciated.

Regards,
Tom

"Tom" wrote in message
.. .
Hi,

My macro first sorts Column A which contains a string of text
alphabetically. It then compares the text down each consecutive row and
prints, "Repeated Entry" in Column B next to it if they are found. It then
sorts Column A:B alphabetically along Column B. At this point and to do a
repetition, For N = 1 to 100 is used. It then searches for the words
"Repeated Entry" and deletes that row. Then comes, Next N. Here is where I
need some help. If there are less than 100 "Repeated Entry" lines, I get
the message,
"Run time error '91': Object variable or With block variable not set". The
macro execution then stops. How can I error trap this so as to allow the
execution to continue on?

TIA
Tom





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
VB Codes bowling Excel Discussion (Misc queries) 0 July 30th 07 07:02 PM
ZIP CODES js42 Excel Worksheet Functions 2 August 5th 05 03:59 PM
Am I asking to much from vb codes? Mr. G. Excel Worksheet Functions 0 July 14th 05 10:36 PM
VBA Codes smck Excel Worksheet Functions 2 May 11th 05 10:03 AM
Zip Codes [email protected] Excel Discussion (Misc queries) 10 November 27th 04 05:23 PM


All times are GMT +1. The time now is 12:46 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"