Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Worksheets looping.

'Modification of Tom Ogilvy's ABC
Sub ABC()
Dim rw As Long, i As Long
Dim cell As Range
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
If sh.Name < "Sheet1" Then
sh.Cells.Sort Key1:=sh.Range("B1"), Header:=xlNo
rw = sh.Cells(sh.Rows.Count, 1).End(xlUp).Row
sh.Columns(1).Insert
For i = rw To 2 Step -1
Set cell = sh.Cells(i, 3)
If
Application.WorksheetFunction.CountA(cell.EntireRo w.Cells) = 0 Then
sh.Rows(i).Delete
Set cell = sh.Cells(i, 3)
End If
If cell < cell.Offset(-1, 0) Then
sh.Rows(i).Insert
sh.Cells(i, 1) = sh.Cells(i + 1, 3)
If sh.Cells(i, 1) = "" Then sh.Cells(i, 1) = "No Lead"
End If
Next
sh.Rows(1).Insert
sh.Cells(1, 1) = sh.Cells(2, 3)
End If
Next sh
End Sub


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)
"Sjakkie" wrote in message
...
thanks to tom and jason for the script below.
One last question though. How could i get this to process the macro
through
the worksheet and then go to the next one and keep doing this, But To
exclude
the worksheet named "sheet1". When i try to do a loop it does it all in
the
same worksheet......




'Modification of Tom Ogilvy's ABC
Sub ABC()
Dim rw As Long, i As Long
Dim cell As Range
Cells.Sort Key1:=Range("B1"), Header:=xlNo
rw = Cells(Rows.Count, 1).End(xlUp).Row
Columns(1).Insert
For i = rw To 2 Step -1
Set cell = Cells(i, 3)
If Application.WorksheetFunction.CountA(cell.EntireRo w.Cells) = 0
Then
Rows(i).Delete
Set cell = Cells(i, 3)
End If
If cell < cell.Offset(-1, 0) Then
Rows(i).Insert
Cells(i, 1) = Cells(i + 1, 3)
If Cells(i, 1) = "" Then
Cells(i, 1) = "No Lead"
End If
End If
Next
Rows(1).Insert
Cells(1, 1) = Cells(2, 3)
End Sub



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
Looping through Worksheets Steve Excel Programming 7 July 12th 05 07:56 PM
Looping through Worksheets Kirk P. Excel Programming 1 February 7th 05 05:14 PM
looping through worksheets from addin BrianB Excel Programming 0 October 9th 03 09:05 AM
looping through worksheets Alex ekster Excel Programming 1 July 21st 03 03:16 AM
looping through worksheets alex Excel Programming 0 July 20th 03 06:43 PM


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