#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default Error in a Macro

Hi:

The below macro is supposed to delete the complete rows when the cells in
columm E are not equal to "CNR001". I am getting an error in rows.Delete

Could anyone help me checking out this macro for me.

Thanks.

Sub NoProReport()

Range("E1").Select

For Carrier = 1 To 1000

If Carrier = "CNR001" Then
ActiveCell(1, 0).Select

Else
rows.Delete

End If
Next Carrier

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default Error in a Macro

Change your "rows.delete" line and replace with the following:

Rows(Application.ActiveCell.Row).EntireRow.Delete

--
Kevin Backmann


"orquidea" wrote:

Hi:

The below macro is supposed to delete the complete rows when the cells in
columm E are not equal to "CNR001". I am getting an error in rows.Delete

Could anyone help me checking out this macro for me.

Thanks.

Sub NoProReport()

Range("E1").Select

For Carrier = 1 To 1000

If Carrier = "CNR001" Then
ActiveCell(1, 0).Select

Else
rows.Delete

End If
Next Carrier

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default Error in a Macro

Thanks Kevin for your answer. I run the macro but it deleted all the rows.
I must have made a mistake in other part of the macro. If it is not too
much to ask could you check it out?

Thanks,

"Kevin B" wrote:

Change your "rows.delete" line and replace with the following:

Rows(Application.ActiveCell.Row).EntireRow.Delete

--
Kevin Backmann


"orquidea" wrote:

Hi:

The below macro is supposed to delete the complete rows when the cells in
columm E are not equal to "CNR001". I am getting an error in rows.Delete

Could anyone help me checking out this macro for me.

Thanks.

Sub NoProReport()

Range("E1").Select

For Carrier = 1 To 1000

If Carrier = "CNR001" Then
ActiveCell(1, 0).Select

Else
rows.Delete

End If
Next Carrier

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Error in a Macro

Option Explicit
Sub NoProReport2()

dim iRow as long
with worksheets("Somesheetnamehere")
for irow = 1000 to 1 step -1
if lcase(.cells(irow,"E").value) = lcase("CNR001") the
.rows(irow).delete
end if
next irow
end with

End Sub

You could be overestimating where to start. If you wanted to start in the last
used row in column E, you could use this line instead:

for irow = .cells(.rows.count,"E").end(xlup).row to 1 step -1

And by starting at the bottom and working your way to the top, you'll find that
it's much easier. You don't have to keep track of what row you're on and if it
was deleted or if it was kept.

orquidea wrote:

Hi:

The below macro is supposed to delete the complete rows when the cells in
columm E are not equal to "CNR001". I am getting an error in rows.Delete

Could anyone help me checking out this macro for me.

Thanks.

Sub NoProReport()

Range("E1").Select

For Carrier = 1 To 1000

If Carrier = "CNR001" Then
ActiveCell(1, 0).Select

Else
rows.Delete

End If
Next Carrier

End Sub


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default Error in a Macro

Hi Dave

Thanks for your answer. I tried your version but it is deleting the rows
with CNR001 and I want it to delete the rows that don't read CNR001 on columm
E.



"Dave Peterson" wrote:

Option Explicit
Sub NoProReport2()

dim iRow as long
with worksheets("Somesheetnamehere")
for irow = 1000 to 1 step -1
if lcase(.cells(irow,"E").value) = lcase("CNR001") the
.rows(irow).delete
end if
next irow
end with

End Sub

You could be overestimating where to start. If you wanted to start in the last
used row in column E, you could use this line instead:

for irow = .cells(.rows.count,"E").end(xlup).row to 1 step -1

And by starting at the bottom and working your way to the top, you'll find that
it's much easier. You don't have to keep track of what row you're on and if it
was deleted or if it was kept.

orquidea wrote:

Hi:

The below macro is supposed to delete the complete rows when the cells in
columm E are not equal to "CNR001". I am getting an error in rows.Delete

Could anyone help me checking out this macro for me.

Thanks.

Sub NoProReport()

Range("E1").Select

For Carrier = 1 To 1000

If Carrier = "CNR001" Then
ActiveCell(1, 0).Select

Else
rows.Delete

End If
Next Carrier

End Sub


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Error in a Macro

Change this portion:


orquidea wrote:

Hi Dave

Thanks for your answer. I tried your version but it is deleting the rows
with CNR001 and I want it to delete the rows that don't read CNR001 on columm
E.

"Dave Peterson" wrote:

Option Explicit
Sub NoProReport2()

dim iRow as long
with worksheets("Somesheetnamehere")
for irow = 1000 to 1 step -1
if lcase(.cells(irow,"E").value) = lcase("CNR001") the
.rows(irow).delete
end if
next irow
end with

End Sub

You could be overestimating where to start. If you wanted to start in the last
used row in column E, you could use this line instead:

for irow = .cells(.rows.count,"E").end(xlup).row to 1 step -1

And by starting at the bottom and working your way to the top, you'll find that
it's much easier. You don't have to keep track of what row you're on and if it
was deleted or if it was kept.

orquidea wrote:

Hi:

The below macro is supposed to delete the complete rows when the cells in
columm E are not equal to "CNR001". I am getting an error in rows.Delete

Could anyone help me checking out this macro for me.

Thanks.

Sub NoProReport()

Range("E1").Select

For Carrier = 1 To 1000

If Carrier = "CNR001" Then
ActiveCell(1, 0).Select

Else
rows.Delete

End If
Next Carrier

End Sub


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Error in a Macro

Oops.

Change this portion:
if lcase(.cells(irow,"E").value) = lcase("CNR001") then
.rows(irow).delete
end if

to

if lcase(.cells(irow,"E").value) = lcase("CNR001") then
'do nothing
else
.rows(irow).delete
end if

You may want to use 1000 to 1 now. Or use something else to determine what the
last row is.


orquidea wrote:

Hi Dave

Thanks for your answer. I tried your version but it is deleting the rows
with CNR001 and I want it to delete the rows that don't read CNR001 on columm
E.

"Dave Peterson" wrote:

Option Explicit
Sub NoProReport2()

dim iRow as long
with worksheets("Somesheetnamehere")
for irow = 1000 to 1 step -1
if lcase(.cells(irow,"E").value) = lcase("CNR001") the
.rows(irow).delete
end if
next irow
end with

End Sub

You could be overestimating where to start. If you wanted to start in the last
used row in column E, you could use this line instead:

for irow = .cells(.rows.count,"E").end(xlup).row to 1 step -1

And by starting at the bottom and working your way to the top, you'll find that
it's much easier. You don't have to keep track of what row you're on and if it
was deleted or if it was kept.

orquidea wrote:

Hi:

The below macro is supposed to delete the complete rows when the cells in
columm E are not equal to "CNR001". I am getting an error in rows.Delete

Could anyone help me checking out this macro for me.

Thanks.

Sub NoProReport()

Range("E1").Select

For Carrier = 1 To 1000

If Carrier = "CNR001" Then
ActiveCell(1, 0).Select

Else
rows.Delete

End If
Next Carrier

End Sub


--

Dave Peterson


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default Error in a Macro

Thanks Dave It worked.

Just my last question, How can I program it so instead of going through 1 -
1000 it goes to the last row with data and stops there. I ususally have
less data than 1000 but the number is irregular.

Thanks again







"Dave Peterson" wrote:

Oops.

Change this portion:
if lcase(.cells(irow,"E").value) = lcase("CNR001") then
.rows(irow).delete
end if

to

if lcase(.cells(irow,"E").value) = lcase("CNR001") then
'do nothing
else
.rows(irow).delete
end if

You may want to use 1000 to 1 now. Or use something else to determine what the
last row is.


orquidea wrote:

Hi Dave

Thanks for your answer. I tried your version but it is deleting the rows
with CNR001 and I want it to delete the rows that don't read CNR001 on columm
E.

"Dave Peterson" wrote:

Option Explicit
Sub NoProReport2()

dim iRow as long
with worksheets("Somesheetnamehere")
for irow = 1000 to 1 step -1
if lcase(.cells(irow,"E").value) = lcase("CNR001") the
.rows(irow).delete
end if
next irow
end with

End Sub

You could be overestimating where to start. If you wanted to start in the last
used row in column E, you could use this line instead:

for irow = .cells(.rows.count,"E").end(xlup).row to 1 step -1

And by starting at the bottom and working your way to the top, you'll find that
it's much easier. You don't have to keep track of what row you're on and if it
was deleted or if it was kept.

orquidea wrote:

Hi:

The below macro is supposed to delete the complete rows when the cells in
columm E are not equal to "CNR001". I am getting an error in rows.Delete

Could anyone help me checking out this macro for me.

Thanks.

Sub NoProReport()

Range("E1").Select

For Carrier = 1 To 1000

If Carrier = "CNR001" Then
ActiveCell(1, 0).Select

Else
rows.Delete

End If
Next Carrier

End Sub

--

Dave Peterson


--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Error in a Macro

If you can pick out a column that you can use to determine the last row (I used
column E), you could use this line:

for irow = .cells(.rows.count,"E").end(xlup).row to 1 step -1

instead.

Change "E" to whatever column letter can be used.

orquidea wrote:

Thanks Dave It worked.

Just my last question, How can I program it so instead of going through 1 -
1000 it goes to the last row with data and stops there. I ususally have
less data than 1000 but the number is irregular.

Thanks again

"Dave Peterson" wrote:

Oops.

Change this portion:
if lcase(.cells(irow,"E").value) = lcase("CNR001") then
.rows(irow).delete
end if

to

if lcase(.cells(irow,"E").value) = lcase("CNR001") then
'do nothing
else
.rows(irow).delete
end if

You may want to use 1000 to 1 now. Or use something else to determine what the
last row is.


orquidea wrote:

Hi Dave

Thanks for your answer. I tried your version but it is deleting the rows
with CNR001 and I want it to delete the rows that don't read CNR001 on columm
E.

"Dave Peterson" wrote:

Option Explicit
Sub NoProReport2()

dim iRow as long
with worksheets("Somesheetnamehere")
for irow = 1000 to 1 step -1
if lcase(.cells(irow,"E").value) = lcase("CNR001") the
.rows(irow).delete
end if
next irow
end with

End Sub

You could be overestimating where to start. If you wanted to start in the last
used row in column E, you could use this line instead:

for irow = .cells(.rows.count,"E").end(xlup).row to 1 step -1

And by starting at the bottom and working your way to the top, you'll find that
it's much easier. You don't have to keep track of what row you're on and if it
was deleted or if it was kept.

orquidea wrote:

Hi:

The below macro is supposed to delete the complete rows when the cells in
columm E are not equal to "CNR001". I am getting an error in rows.Delete

Could anyone help me checking out this macro for me.

Thanks.

Sub NoProReport()

Range("E1").Select

For Carrier = 1 To 1000

If Carrier = "CNR001" Then
ActiveCell(1, 0).Select

Else
rows.Delete

End If
Next Carrier

End Sub

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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 Error Carl Excel Worksheet Functions 1 January 31st 07 05:44 PM
Macro Error The Toasterman Excel Discussion (Misc queries) 4 June 30th 06 01:44 PM
Macro error : Application-defined or object-defined error Joe Excel Discussion (Misc queries) 3 January 27th 06 02:32 PM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Macro error - more help please! Anthony Excel Discussion (Misc queries) 2 March 22nd 05 03:02 PM


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