Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default worksheet loop

Public Sub Processteams()
Dim iLastRow As Long
Dim i As Long
Dim iCol As Long
Dim iRow As Long
Dim sh as Worksheet

for each sh in Worksheets
if sh.Name < "Sheet1" and sh.Name < "Sheet2" then
with sh
.Rows("1:300").Insert Shift:=xlToRight
iLastRow = .Cells(.Rows.Count, "o").End(xlUp).Row
For i = 1 To iLastRow
iCol = 0
On Error Resume Next
iCol = Application.Match(.Cells(i, "o").Value, _
.Rows(1), 0)
On Error GoTo 0
If iCol = 0 Then
iCol = .Range("a1").End(xlToRight).Column + 1
If iCol .Columns.Count Then
iCol = IIf(.Range("a1").Value = "", 1, 2)
End If
.Cells(1, iCol).Value = .Cells(i, "o").Value
iRow = 2
.Cells(1, iCol).Interior.ColorIndex = 37
Else
iRow = .Cells(1, iCol).End(xlDown).Row + 1
End If
.Cells(iRow, iCol).Value = .Cells(i, "c").Value
Next i
End With
End if
Next sh
End Sub

--
Regards,
Tom Ogilvy

"Sjakkie" wrote:

how can i adapt the following script to run on all worksheets in a workbook
but to ignore and go to the next sheet if the sheet name equals "Sheet1" or
"Sheet2"

Public Sub Processteams()
Dim iLastRow As Long
Dim i As Long
Dim iCol As Long
Dim iRow As Long
With ActiveSheet


Rows("1:300").Insert Shift:=xlToRight
iLastRow = .Cells(.Rows.Count, "o").End(xlUp).Row
For i = 1 To iLastRow
iCol = 0
On Error Resume Next
iCol = Application.Match(.Cells(i, "o").Value, _
ActiveSheet.Rows(1), 0)
On Error GoTo 0
If iCol = 0 Then
iCol = ActiveSheet.Range("a1").End(xlToRight).Column + 1
If iCol .Columns.Count Then
iCol = IIf(ActiveSheet.Range("a1").Value = "", 1, 2)
End If
ActiveSheet.Cells(1, iCol).Value = .Cells(i, "o").Value
iRow = 2
ActiveSheet.Cells(1, iCol).Interior.ColorIndex = 37
Else
iRow = ActiveSheet.Cells(1, iCol).End(xlDown).Row + 1
End If
ActiveSheet.Cells(iRow, iCol).Value = .Cells(i, "c").Value
Next i
End With
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
Worksheet loop won't loop L. Howard Kittle Excel Programming 4 March 17th 06 12:56 AM
Do loop to add a new worksheet Alex Excel Programming 2 August 19th 04 11:35 PM
how do you loop through each worksheet? dundonald Excel Programming 16 January 11th 04 02:20 PM
worksheet loop scott[_8_] Excel Programming 8 November 17th 03 09:49 PM
How? Macro to copy range to new worksheet, name new worksheet, loop Repoman Excel Programming 9 October 9th 03 01:45 PM


All times are GMT +1. The time now is 08:50 PM.

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"