ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Not cycling through each sheet (https://www.excelbanter.com/excel-programming/351037-not-cycling-through-each-sheet.html)

Michael Smith

Not cycling through each sheet
 
This code is not working for me...I want to cycle through each sheet in
my workbook and run and IF statement. It is not cycling through my
sheets, please help! TIA! - mike


Range("A1").Select
Selection.End(xlDown).Select
Dim TodaysDate
TodaysDate = ActiveCell.Text

Dim WbMain As Workbook
Dim wb As Workbook
Dim Sh As Worksheet

Application.ScreenUpdating = False
Application.EnableEvents = False

Set WbMain = ActiveWorkbook
For Each Sh In WbMain.Worksheets
Range("A1").Select
Selection.End(xlDown).Select
If ActiveCell.Value = TodaysDate Then
Range("A1").End(xlDown).Offset(1, 0).FormulaR1C1 = "=today()"
Range("A1").End(xlDown).Offset(0, 1).Formula = "0"
Columns("A:A").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Range("A1").Select
End If
Next Sh




*** Sent via Developersdex http://www.developersdex.com ***

Toppers

Not cycling through each sheet
 
Hi,
Try:

For Each Sh In WbMain.Worksheets
sh.activate

"Michael Smith" wrote:

This code is not working for me...I want to cycle through each sheet in
my workbook and run and IF statement. It is not cycling through my
sheets, please help! TIA! - mike


Range("A1").Select
Selection.End(xlDown).Select
Dim TodaysDate
TodaysDate = ActiveCell.Text

Dim WbMain As Workbook
Dim wb As Workbook
Dim Sh As Worksheet

Application.ScreenUpdating = False
Application.EnableEvents = False

Set WbMain = ActiveWorkbook
For Each Sh In WbMain.Worksheets
Range("A1").Select
Selection.End(xlDown).Select
If ActiveCell.Value = TodaysDate Then
Range("A1").End(xlDown).Offset(1, 0).FormulaR1C1 = "=today()"
Range("A1").End(xlDown).Offset(0, 1).Formula = "0"
Columns("A:A").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Range("A1").Select
End If
Next Sh




*** Sent via Developersdex http://www.developersdex.com ***


Don Guillett

Not cycling through each sheet
 
try this from anywhere in the workbook.
Sub dobetter()
td = sheets("sheet1").Cells(Rows.Count, "a").End(xlUp)
For Each Sh In Worksheets
slr = Sh.Cells(Rows.Count, "a").End(xlUp).Row
If Sh.Name < "Sheet1" And Sh.Cells(slr, 1) = td Then
Sh.Range("a1:a" & slr) = Date
Sh.Range("b2:b" & slr) = 0
End If
Next Sh
End Sub

--
Don Guillett
SalesAid Software

"Michael Smith" wrote in message
...
This code is not working for me...I want to cycle through each sheet in
my workbook and run and IF statement. It is not cycling through my
sheets, please help! TIA! - mike


Range("A1").Select
Selection.End(xlDown).Select
Dim TodaysDate
TodaysDate = ActiveCell.Text

Dim WbMain As Workbook
Dim wb As Workbook
Dim Sh As Worksheet

Application.ScreenUpdating = False
Application.EnableEvents = False

Set WbMain = ActiveWorkbook
For Each Sh In WbMain.Worksheets
Range("A1").Select
Selection.End(xlDown).Select
If ActiveCell.Value = TodaysDate Then
Range("A1").End(xlDown).Offset(1, 0).FormulaR1C1 = "=today()"
Range("A1").End(xlDown).Offset(0, 1).Formula = "0"
Columns("A:A").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Range("A1").Select
End If
Next Sh




*** Sent via Developersdex
http://www.developersdex.com ***



Michael Smith

Not cycling through each sheet
 
both work wonderfully...thank you mucho.



*** Sent via Developersdex http://www.developersdex.com ***

Don Guillett

Not cycling through each sheet
 
Please take notice of the fact that it is NOT necessary to activate or
select. Both are poor coding practices that only slow down the process.

--
Don Guillett
SalesAid Software

"Michael Smith" wrote in message
...
both work wonderfully...thank you mucho.



*** Sent via Developersdex
http://www.developersdex.com ***




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

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