vba loop not moving to next worksheet

meghanalissa

New Member
Joined
Jan 14, 2013
Messages
20
I have a built two macros--one that calls the other. The first one copys down the formula in the last row, then paste's the values of the last cell. This code works if I just run it on one sheet

Code:
Sub CopyDownAndPaste()

  Dim Col As Range
  For Each Col In Range("C:U").Columns
    With Cells(Rows.Count, Col.Column).End(xlUp)
      .Copy .Offset(1)
      .Value = .Value
    End With
  Next
End Sub

However, when I try to call it in the code below so that it will loop through all visible sheets in the workbook, it just repeats on the original tab.

Code:
Sub UpdateAllSheets()

    Dim ws As Worksheet
     For Each ws In ActiveWorkbook.Worksheets
    If ws.Visible Then ws.Select (False)
    Application.Run ("CopyDownAndPaste")
    Next
    
    'Put top of page in view & select A1
    For Each ws In ActiveWorkbook.Worksheets
    If ws.Visible Then ws.Select (False)
    SendKeys ("^{HOME}")
    Range("A1").Select
    Next
    ActiveSheet.Select
    
End Sub

Can anyone tell me what I am doing wrong that is not allowing my loop to proceed to the next worksheet?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try removing the False parameter wherever you call the ws.Select method.

Edit: More info: By passing False in the Replace parameter of the Select method you're adding the worksheet to the selection but the first worksheet remains the active one.
 
Upvote 0
Try removing the False parameter wherever you call the ws.Select method.

Edit: More info: By passing False in the Replace parameter of the Select method you're adding the worksheet to the selection but the first worksheet remains the active one.

Thank you, Angel! Solved another one :) I got the code with the false from a forum and it worked in my other worksheet, but it caused the problem here...strange, but great to know.
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,086
Members
449,206
Latest member
ralemanygarcia

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