Loop running on same sheet twice & skipping desired sheet.

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
758
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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,215,633
Messages
6,125,929
Members
449,274
Latest member
mrcsbenson

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