Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default error in macro (next related i think)

Hi, i use the following macro to delete rows from a worksheet

Sheets("MOBILE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

eveerything works fine, now i want to use it to delete rows 4 differest
worksheets in the same workbook so i figure i make it like this:


Sub MOBILEKAPNISIS()

Sheets("MOBILE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("VOICE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("BLACKBERRY TOTAL").Select
lr = Cells(Rows.Count, "g").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "g") < "overhead" And _
Cells(i, "g") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("DATA TOTAL").Select
lr = Cells(Rows.Count, "g").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "g") < "overhead" And _
Cells(i, "g") < "OPERATIONS" Then Rows(i).Delete
Next i

End Sub

but nope it dosent work, anyone can help me out?

thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default error in macro (next related i think)

Hi steven.
Try to change:

If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete


as:

If Cells(i, "e") < "overhead" Or _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete


Probably the cells cannot contain "overhead" AND
"OPERATIONS" but OR the First OR the second.
Regards
Eliano

On 3 Giu, 23:31, steven wrote:
Hi, i use the following macro to delete rows from a worksheet

Sheets("MOBILE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

eveerything works fine, now i want to use it to delete rows 4 differest
worksheets in the same workbook so i figure i make it like this:

Sub MOBILEKAPNISIS()

Sheets("MOBILE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("VOICE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("BLACKBERRY TOTAL").Select
lr = Cells(Rows.Count, "g").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "g") < "overhead" And _
Cells(i, "g") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("DATA TOTAL").Select
lr = Cells(Rows.Count, "g").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "g") < "overhead" And _
Cells(i, "g") < "OPERATIONS" Then Rows(i).Delete
Next i

End Sub

but nope it dosent work, anyone can help me out?

thanks in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default error in macro (next related i think)

Your code works. I set up as test with data in columns E and G and it
deleted the rows that did not have overhead or OPERATIONS in those columns.
The problem might be in the assignment of the last row. Try using the sheet
designation for each variable assignment for the last row like this example.

lr = Sheets(MOBILE TOTAL").Cells(Rows.Count, "E").End(xlUp).Row

When I checked the last row in my sample, using your original code, it was
still using the last row for column E on a worksheet that should have been
for column G. If column E had been blank then it would have done nothing.
By qualifying the Cells designation with the worksheet, it then used column g
to find the last row.
Check it out and see if it solves the problem. If not, then post back.

"steven" wrote:

Hi, i use the following macro to delete rows from a worksheet

Sheets("MOBILE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

eveerything works fine, now i want to use it to delete rows 4 differest
worksheets in the same workbook so i figure i make it like this:


Sub MOBILEKAPNISIS()

Sheets("MOBILE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("VOICE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("BLACKBERRY TOTAL").Select
lr = Cells(Rows.Count, "g").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "g") < "overhead" And _
Cells(i, "g") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("DATA TOTAL").Select
lr = Cells(Rows.Count, "g").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "g") < "overhead" And _
Cells(i, "g") < "OPERATIONS" Then Rows(i).Delete
Next i

End Sub

but nope it dosent work, anyone can help me out?

thanks in advance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default error in macro (next related i think)

I'm not so sure that is a good idea. eliano. Using Or would cause it to
equal True if one of the words appear in the cell. I believe he wants it to
be true only if neither of the the words appear.

"eliano" wrote:

Hi steven.
Try to change:

If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete


as:

If Cells(i, "e") < "overhead" Or _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete


Probably the cells cannot contain "overhead" AND
"OPERATIONS" but OR the First OR the second.
Regards
Eliano

On 3 Giu, 23:31, steven wrote:
Hi, i use the following macro to delete rows from a worksheet

Sheets("MOBILE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

eveerything works fine, now i want to use it to delete rows 4 differest
worksheets in the same workbook so i figure i make it like this:

Sub MOBILEKAPNISIS()

Sheets("MOBILE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("VOICE TOTAL").Select
lr = Cells(Rows.Count, "e").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("BLACKBERRY TOTAL").Select
lr = Cells(Rows.Count, "g").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "g") < "overhead" And _
Cells(i, "g") < "OPERATIONS" Then Rows(i).Delete
Next i

Sheets("DATA TOTAL").Select
lr = Cells(Rows.Count, "g").End(xlUp).Row
For i = lr To 2 Step -1
If Cells(i, "g") < "overhead" And _
Cells(i, "g") < "OPERATIONS" Then Rows(i).Delete
Next i

End Sub

but nope it dosent work, anyone can help me out?

thanks in advance.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default error in macro (next related i think)

Hi JL.

Probably, due to my poor english, i have not understood the question.
Many thanks & regards,
Eliano


On 4 Giu, 05:41, JLGWhiz wrote:
I'm not so sure that is a good idea.eliano. *Using Or would cause it to
equal True if one of the words appear in the cell. *I believe he wants it to
be true only if neither of the the words appear.



"eliano" wrote:
Hi steven.
Try to change:


If Cells(i, "e") < "overhead" And _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete


as:


If Cells(i, "e") < "overhead" Or _
Cells(i, "e") < "OPERATIONS" Then Rows(i).Delete


Probably the cells cannot contain "overhead" AND
"OPERATIONS" but OR the First OR the second.
Regards
Eliano


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
Run time error related to add-ins Grant Excel Discussion (Misc queries) 0 June 13th 09 03:48 PM
related to error function amit saraf Excel Discussion (Misc queries) 4 November 8th 08 11:57 PM
Error trapping is not working for errors related to files BAC Excel Programming 9 August 10th 07 10:36 PM
Syntax error - FSO related? Damon Excel Programming 1 August 8th 06 11:59 AM
macro related Ankur Excel Discussion (Misc queries) 3 August 17th 05 11:26 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"