ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop Question (https://www.excelbanter.com/excel-programming/384071-loop-question.html)

Alan P

Loop Question
 
I'm trying to loop through a workbook, test to see if the worksheet name is
numeric, and if so go to a subroutine(MoveData), if not, continue to the next
worksheet. I tried the following but can't get it to work, it has a problem
with the Next line. Anyone have any ideas?

Thanks, Alan

Sub Move_All_Data()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
If IsNumeric(ActiveSheet.Name) Then
MoveData
Else
Next ws
End Sub

Jay

Loop Question
 
Try this modification which deletes the Else clause, cleans up the Next line,
and adusts the Then clause...

Sub Move_All_Data()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
If IsNumeric(ActiveSheet.Name) Then MoveData
Next 'ws
End Sub
--
Jay


"Alan P" wrote:

I'm trying to loop through a workbook, test to see if the worksheet name is
numeric, and if so go to a subroutine(MoveData), if not, continue to the next
worksheet. I tried the following but can't get it to work, it has a problem
with the Next line. Anyone have any ideas?

Thanks, Alan

Sub Move_All_Data()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
If IsNumeric(ActiveSheet.Name) Then
MoveData
Else
Next ws
End Sub


Don Guillett

Loop Question
 
try this. Test and then uncomment the commented line

Sub eachnumericws()
For Each ws In Worksheets
If IsNumeric(ws.Name) Then MsgBox ws.Name 'TEST
'If IsNumeric(ws.Name) Then movedata
Next
End Sub


--
Don Guillett
SalesAid Software

"Alan P" wrote in message
...
I'm trying to loop through a workbook, test to see if the worksheet name
is
numeric, and if so go to a subroutine(MoveData), if not, continue to the
next
worksheet. I tried the following but can't get it to work, it has a
problem
with the Next line. Anyone have any ideas?

Thanks, Alan

Sub Move_All_Data()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
If IsNumeric(ActiveSheet.Name) Then
MoveData
Else
Next ws
End Sub




Alan P

Loop Question
 
Thanks Jay it looks like that did the trick.

Alan

"Jay" wrote:

Try this modification which deletes the Else clause, cleans up the Next line,
and adusts the Then clause...

Sub Move_All_Data()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
If IsNumeric(ActiveSheet.Name) Then MoveData
Next 'ws
End Sub
--
Jay


"Alan P" wrote:

I'm trying to loop through a workbook, test to see if the worksheet name is
numeric, and if so go to a subroutine(MoveData), if not, continue to the next
worksheet. I tried the following but can't get it to work, it has a problem
with the Next line. Anyone have any ideas?

Thanks, Alan

Sub Move_All_Data()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
If IsNumeric(ActiveSheet.Name) Then
MoveData
Else
Next ws
End Sub


Don Guillett

Loop Question
 

Selections NOT necessary

--
Don Guillett
SalesAid Software

"Alan P" wrote in message
...
Thanks Jay it looks like that did the trick.

Alan

"Jay" wrote:

Try this modification which deletes the Else clause, cleans up the Next
line,
and adusts the Then clause...

Sub Move_All_Data()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
If IsNumeric(ActiveSheet.Name) Then MoveData
Next 'ws
End Sub
--
Jay


"Alan P" wrote:

I'm trying to loop through a workbook, test to see if the worksheet
name is
numeric, and if so go to a subroutine(MoveData), if not, continue to
the next
worksheet. I tried the following but can't get it to work, it has a
problem
with the Next line. Anyone have any ideas?

Thanks, Alan

Sub Move_All_Data()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
If IsNumeric(ActiveSheet.Name) Then
MoveData
Else
Next ws
End Sub





All times are GMT +1. The time now is 10:17 AM.

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