ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   worksheet loop (https://www.excelbanter.com/excel-programming/378944-re-worksheet-loop.html)

Don Guillett

worksheet loop
 

for each ws in worksheets
if ws.name < "Sheet1" and ws. name < "Sheet2" then
with ws
.. 'watch your dot placement
end with
next ws

--
Don Guillett
SalesAid Software

"Sjakkie" wrote in message
...
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




Sjakkie

worksheet loop
 
sorry, this is all toatally new and i am trying to understand it more. Could
you input the code where it is suppossed to go and what to replace.... it
would be much appreciatted.



"Don Guillett" wrote:


for each ws in worksheets
if ws.name < "Sheet1" and ws. name < "Sheet2" then
with ws
.. 'watch your dot placement
end with
next ws

--
Don Guillett
SalesAid Software

"Sjakkie" wrote in message
...
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






All times are GMT +1. The time now is 09:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com