Home > Mobile >  Macro that sum different values between worksheets
Macro that sum different values between worksheets

Time:12-06

I'm new to the platform and I was wondering if there is a way to write in a "main" sheet the value of total characters for every first column in every sheet in the file

ex: 1st sheet -> count of total characters -> write down into "main sheet" CELL L1 then 2st sheet -> count of total characters -> write down into "main sheet" CELL L2 ...

Here is the code, I've already tried looking for an answer in stack overflow but it doesn't work

Tried this:

Dim Sheets As Variant
Dim Sheet As Variant
Sheets = Array("1", "2", "3", "4",..."12")

For Each Sheet In Sheets
   
 For Rowref = 1 To 12
        totalchar = totalchar   Len(Worksheets(Sheet).Range("B2:B100000").Value)
        Worksheets("MAIN").Range ("L" & Rowref)
    Next Rowref
Next Sheet

CodePudding user response:

You can use a For Each loop in order to run through all the sheets, like in this example:

Sub test()
Dim sum As Integer
sum = 0
For Each w In ActiveWorkbook.Worksheets
  sum = sum   w.Range("A1").Value
Next
  MsgBox (sum)
End Sub

Have fun :-)

  • Related