Duda con macro para recolectar sumatoria de varias hojas

En el pasado me apoyaron con un macro para recolectar información de un libro:

En la hoja OVERALL, se recolecta toda la información de la celdas a manera de lista con el nombre de la persona, ingresos y egresos: quedando D2, D39, H39.

Quedando una lista asi en la hoja "overall":

y el codigo es el siguiente: 

Sub RecollectSumm()
'
Set h1 = Sheets("OVERALL")
h1.Rows("2:" & Rows.Count).ClearContents
fila = 2
For Each h In Sheets
Select Case UCase(h.Name)
Case "OVERALL", "ORIGINAL", "OVERRIDES", "DATA"
Case Else
h1.Range("A" & fila & ":C" & fila) = Array(h.[D2], h.[D39], h.[H39])
fila = fila + 1
End Select
Next
MsgBox "Done!"
End If
End Sub

Ahora necesito una macro muy parecida pero que haga lo siguiente: 

Que me traiga a la hoja "Recollect", el contenido de la celda D2, la sumatoria de D10:D20, la sumatoria de H10:H20 y al final la resta de SUMA (D10:D20) - SUMA (H10:H20) de cada hoja del libro, excluyendo las hojas "OVERALL", "ORIGINAL", "OVERRIDES", "DATA", como en el macro pasado.

Les agradecería mucho de su ayuda, ya que el anterior código me queda claro, pero agregar la sumatoria de esos rangos me confunde, ¿alguien puede resolver mi duda?.

1 Respuesta

Respuesta
2

Prueba la siguiente macro:

Sub Suma()
  Dim h1 As Worksheet, h As Worksheet, fila As Long
  '
  Application.ScreenUpdating = False
  Set h1 = Sheets("Recollect")
  h1.Rows("2:" & Rows.Count).ClearContents
  fila = 2
  '
  For Each h In Sheets
    Select Case UCase(h.Name)
    Case "OVERALL", "ORIGINAL", "OVERRIDES", "DATA", "RECOLLECT"
    Case Else
      h1.Range("A" & fila) = h.[D2]
      h1.Range("B" & fila) = WorksheetFunction.Sum(h.[D10:D20])
      h1.Range("C" & fila) = WorksheetFunction.Sum(h.[H10:H20])
      h1.Range("D" & fila) = h1.Range("B" & fila) - h1.Range("C" & fila)
      fila = fila + 1
    End Select
  Next
  MsgBox "Done!"
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas