Loop running on same sheet twice & skipping desired sheet.

countryfan_nt

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

Forum statistics

Threads
1,081,421
Messages
5,358,584
Members
400,505
Latest member
JacquiT

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top