+ Reply to Thread
Results 1 to 2 of 2

Macro looping through several worksheets in one workbook

  1. #1
    Registered User
    Join Date
    09-26-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    24

    Macro looping through several worksheets in one workbook

    Hi, I found a code on this forum to loop through every worksheet in the workbook and write "hello" in cell A1 for every worksheet. Instead of saying hello in A1 on every worksheet, I want the code to average numbers in column C in groups of four in each worksheet and have it recorded in column A. Here is my code:

    Sub WorksheetLoops()

    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets
    If InStr("Price", ws.Name) = 0 Then
    Columns("A:A").ColumnWidth = 4.86
    Range("A9").Select
    ActiveCell.FormulaR1C1 = "=AVERAGE(R[-3]C[2]:RC[2])"
    Range("A6:A9").Select
    Selection.AutoFill Destination:=Range("A6:A101"), Type:=xlFillDefault
    Range("A6:A101").Select
    End If
    Next ws

    End Sub


    For some reason it just runs the loop in the first worksheet. Does anyone know why?

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro looping through several worksheets in one workbook

    Untested
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1