+ Reply to Thread
Results 1 to 2 of 2

Problem with looping and computing in all woorksheets

  1. #1
    Registered User
    Join Date
    11-04-2012
    Location
    Israel
    MS-Off Ver
    Excel 2010
    Posts
    1

    Problem with looping and computing in all woorksheets

    dear all,
    I am trying to compute an average of certain range (which depends on user input) in every worksheet of the workbook.

    i succeed only in one sheet ("sheet2") and cant make the computation in the other sheets.

    please see the code:

    Dim s As Worksheet
    For Each s In Worksheets

    For m = 1 To 28 '#loop on the row m
    totold = 0
    tot = 0
    For j = column_min To column_max '#loop on the column j - column_min and column_max are integers
    tot = totold + Cells(m, j).Value
    totold = tot
    Next j

    Cells(m, 17).Value = totold / (column_max - column_min + 1)
    Next m '#next row
    Next s '#next sheet


    i have tried to use the "with worksheets ()...end with" but have no success.

    thanks in advance,
    Yohai

  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: Problem with looping and computing in all woorksheets

    Hi, yohai,

    welcome to ExcelForum. Please use Code-Tags for a better readability of the code (as requested by the Forum Rules).

    Maybe you just need to correspond the cells to the worksheets - otherwise the cells will always be taken from the active sheet:

    Please Login or Register  to view this content.
    Code is not tested as neither all variables are dimmed or filled with values.

    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

+ 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