ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Loop worksheets (https://www.excelbanter.com/excel-discussion-misc-queries/215593-loop-worksheets.html)

merry_fay

Loop worksheets
 
Hi,

I have the following code:
Sub Hardcode()
For Each wks In ActiveWorkbook.Sheets
If Range("A4").Value < 400 Then
Call PriorYr
Call Actuals
Call Budget
Call Forecast
Else
End If
Next wks
Call Delete_Datasheets
End Sub

As far as I can see it's all correct, but the sheets aren't looping (next
wks not working). Does anyone know why or have any suggestions?
The total number of sheets in the workbook varies.

Thanks
merry_fay

Luke M

Loop worksheets
 
You didn't say which worksheet range to check.

Sub Hardcode()
For Each wks In ActiveWorkbook.Sheets
If wks.Range("A4").Value < 400 Then
Call PriorYr
Call Actuals
Call Budget
Call Forecast
Else
End If
Next wks
Call Delete_Datasheets
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"merry_fay" wrote:

Hi,

I have the following code:
Sub Hardcode()
For Each wks In ActiveWorkbook.Sheets
If Range("A4").Value < 400 Then
Call PriorYr
Call Actuals
Call Budget
Call Forecast
Else
End If
Next wks
Call Delete_Datasheets
End Sub

As far as I can see it's all correct, but the sheets aren't looping (next
wks not working). Does anyone know why or have any suggestions?
The total number of sheets in the workbook varies.

Thanks
merry_fay


Mike H

Loop worksheets
 
Hi,

the sheets are looping but not the range, try this line

If wks.Range("A4").Value < 400 Then

Mike

"merry_fay" wrote:

Hi,

I have the following code:
Sub Hardcode()
For Each wks In ActiveWorkbook.Sheets
If Range("A4").Value < 400 Then
Call PriorYr
Call Actuals
Call Budget
Call Forecast
Else
End If
Next wks
Call Delete_Datasheets
End Sub

As far as I can see it's all correct, but the sheets aren't looping (next
wks not working). Does anyone know why or have any suggestions?
The total number of sheets in the workbook varies.

Thanks
merry_fay



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

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