+ Reply to Thread
Results 1 to 5 of 5

Go through all worksheets not functioning

Hybrid View

  1. #1
    Registered User
    Join Date
    10-03-2014
    Location
    London, UK
    MS-Off Ver
    Windows 7
    Posts
    3

    Go through all worksheets not functioning

    Hey guys, I'm trying to pull some averages from worksheets that are all formatted the same way. When I run the following I get the
    "September
    August
    Past 12 Months" table at the bottom of the first worksheet (where I put the control button), but nothing on the other pages... Any idea why?

    Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Dim i As Integer
    Dim j As Integer
    
    
    For Each ws In ActiveWorkbook.Worksheets
    
    ws.Activate
    
    Cells(383, 1).Value = "September"
    Cells(384, 1).Value = "August"
    Cells(385, 1).Value = "Past 12 Months"
    
    
    
    j = 2
    
    For i = 1 To 50
    
    If Cells(7, i).Value = "Score" Or Cells(7, i).Value = "Attention" Then
    Cells(382, j).Value = Cells(6, i).Value
    Cells(383, j).Value = Application.Average(Range(Cells(373, i), Cells(344, i)))
    Cells(384, j).Value = Application.Average(Range(Cells(343, i), Cells(313, i)))
    Cells(385, j).Value = Application.Average(Range(Cells(373, i), Cells(9, i)))
    j = j + 1
    End If
    
    Next i
    
    Next ws
    
    End Sub

    Thanks a lot,

    C
    Last edited by clevot; 10-07-2014 at 04:54 AM. Reason: code tags forgotten

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Go through all worksheets not functioning

    Hi, clevot,

    please have a read at Forum Rule#3 to understand why you are asked to add code-tags to your procedure.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    10-03-2014
    Location
    London, UK
    MS-Off Ver
    Windows 7
    Posts
    3

    Re: Go through all worksheets not functioning

    Done, thanks for pointing that out to me HaHoBe

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: Go through all worksheets not functioning

    You're not qualifying your Range calls with a worksheet and because your code is in a worksheet code module, all the unqualified calls refer to that sheet, not the active sheet. Try this:
    Private Sub CommandButton1_Click()
    Dim ws As Worksheet
    Dim i As Integer
    Dim j As Integer
    
    
    For Each ws In ActiveWorkbook.Worksheets
    
    With ws
    
    .Cells(383, 1).Value = "September"
    .Cells(384, 1).Value = "August"
    .Cells(385, 1).Value = "Past 12 Months"
    
    
    
    j = 2
    
    For i = 1 To 50
    
    If .Cells(7, i).Value = "Score" Or .Cells(7, i).Value = "Attention" Then
    .Cells(382, j).Value = .Cells(6, i).Value
    .Cells(383, j).Value = Application.Average(.Range(.Cells(373, i), .Cells(344, i)))
    .Cells(384, j).Value = Application.Average(.Range(.Cells(343, i), .Cells(313, i)))
    .Cells(385, j).Value = Application.Average(.Range(.Cells(373, i), .Cells(9, i)))
    j = j + 1
    End If
    
    Next i
    End With
    Next ws
    
    End Sub
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Registered User
    Join Date
    10-03-2014
    Location
    London, UK
    MS-Off Ver
    Windows 7
    Posts
    3

    Re: Go through all worksheets not functioning

    Brilliant! Thanks a lot romperstomper!

    Cheers

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Zero Functioning
    By vjharry in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-23-2013, 04:20 AM
  2. [SOLVED] Non Functioning HyperLinks
    By alansidman in forum Excel General
    Replies: 1
    Last Post: 11-05-2012, 01:54 PM
  3. [SOLVED] Enter Key Functioning Like Tab Key
    By imauld in forum Excel General
    Replies: 1
    Last Post: 05-18-2012, 01:12 PM
  4. sumif....&row (not functioning)
    By jw01 in forum Excel General
    Replies: 2
    Last Post: 02-15-2011, 12:00 PM
  5. [SOLVED] excel not functioning
    By TUNGANA KURMA RAJU in forum Excel General
    Replies: 1
    Last Post: 10-13-2005, 03:05 AM

Tags for this Thread

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