Is there a reason that this macro does not jump to the next worksheet?

  • Hello,


    I have two macros. One of the macro is designed to loop through all the worksheets in a file and perform the same operations on them. For some reason, this macro is not jumping to the next worksheet and instead is looping through the same worksheet the whole time.


    Here are both of the macros I am using. THe second macro is ugly, but it gets the job done.


    Code
    Sub Edit_Data_Loop()
    Application.ScreenUpdating = False
    Dim wks As Worksheet
    For Each wks In ActiveWorkbook.Worksheets
        wks.Application.Run ("Edit_Data")
        
        Next wks
    End Sub


  • Re: Is there a reason that this macro does not jump to the next worksheet?


    When I step through the second macro, it does do what I want. The problem must be something that I did with the "next wks" piece in the first macro. I am not familiar enough with VBA to know what I am doing wrong.


    Thanks.

  • Re: Is there a reason that this macro does not jump to the next worksheet?


    Try something:


    put


    Code
    Application.ScreenUpdating = True


    as the last line in the first macro (before the end sub)


    I want to be sure that you are not mistaking the fact that the screen doesn't change with the macro not stepping through the sheets.

  • Re: Is there a reason that this macro does not jump to the next worksheet?


    Hello,


    I had it that way before, and I am sure the macro is not stepping to the next worksheet. I was stepping through the macro one line at a time and was running into the same problem.


    I figured out a workaround by having the edit_data code go to the next worksheet at the end of the code sequence instead of relying on the loop to step through the next worksheet.


    Thank you.

  • Re: Is there a reason that this macro does not jump to the next worksheet?


    The code could be re-written so you can pass the worksheet as an argument to Edit_data.


    I've tried to do that but there were some parts of the code that kind of baffled me.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!