Loop running on same sheet twice & skipping desired sheet.

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
765
Hello friends, hope all is well!

The below codes are working, but not as desired.

What is needed: a. Code moves from one sheet to the other.
b. Every time a new sheet is selected a countdown loop (5-0) in cell H2 takes place.
Once countdown reaches 0, a new sheet is selected. once last sheet in workbook is selected,
code goes back to 1st sheet from the right.

The problems: 1. When code is finished with last sheet, it does go to 1st sheet but briefly and countdown is not applied.

2. The countdown runs twice 5-0 in the last sheet; need it to run once only.

Your kind and support is always needed and appreciated in advance!

Code:
Sub MoveNext()
 On Error Resume Next

 If Not ActiveWorkbook Is ThisWorkbook Then Exit Sub

 Sheets(ActiveSheet.Index + 1).Activate

Worksheets("count").Range("H2").Value = 6

Do Until Worksheets("count").Range("H2").Value = 1


If Worksheets("count").Range("H2").Value = 1 Then

Worksheets("count").Range("H2").Value = 6

Else

Worksheets("count").Range("H2").Value = Worksheets("count").Range("H2").Value - 1
Application.Wait (Now + TimeValue("00:00:01"))

End If
Loop


 If Err.Number <> 0 Then

 Sheets(2).Activate
 Range("C3").Select

 End If
 End Sub


Code:
Sub MyMacro()

Call MoveNext
Application.OnTime Now + TimeValue("00:00:01"), "mymacro"

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top