Código:
Sub ConsolidarImportes()
Dim hoja As Worksheet
Dim hojaReporte As Worksheet
Dim filaDestino As Long
Dim letraColumna As String
Dim totalHoja As Double
letraColumna = "B"
On Error Resume Next
Set hojaReporte = ThisWorkbook.Sheets("Reporte General")
If hojaReporte Is Nothing Then
Set hojaReporte = ThisWorkbook.Sheets.Add
hojaReporte.Name = "Reporte General"
Else
hojaReporte.Cells.Clear
End If
On Error GoTo 0
hojaReporte.Range("A1").Value = "Mes"
hojaReporte.Range("B1").Value = "Importe Total"
hojaReporte.Range("A1:B1").Font.Bold = True
filaDestino = 2
For Each hoja In ThisWorkbook.Worksheets
If hoja.Name <> "Reporte General" Then
totalHoja = Application.WorksheetFunction.Sum(hoja.Columns(letraColumna))
hojaReporte.Cells(filaDestino, 1).Value = hoja.Name
hojaReporte.Cells(filaDestino, 2).Value = totalHoja
filaDestino = filaDestino + 1
End If
Next hoja
hojaReporte.Columns("B").NumberFormat = "$ #,##0.00"
hojaReporte.Columns("A:B").AutoFit
MsgBox "¡Reporte completado!", vbInformation
End Sub
Notar que nombramos a la macro «ConsolidarImportes» y que debemos definir la letra de la columna de la cual debemos sumar sus valores en la siguiente línea de código «letraColumna = «B»».
De esta forma logramos consolidar datos en una sola hoja de forma rápida y fácil mediante macros en Excel.
⭐ Si te gustó, por favor regístrate en nuestra Lista de correo y Suscríbete a mi canal de YouTube para que estés siempre enterado de lo nuevo que publicamos