Loop Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top