Mi macro esta mal pero no se que es...

Sub diario()
Dim WS_Count As Integer
Dim I As Integer
WS_Count = ActiveWorkbook.Worksheets.Count
For I = 1 To WS_Count
fecha_buscar = InputBox("que fecha?, te recuerdo que es DD-MM-AA")
If fecha_buscar = ActiveWorkbook.Worksheets(I).Range("G8") Then
sub_sumatoria = ActiveWorkbook.Worksheets(I).Range("G38")
sumatoria = sub_sumatoria + ActiveWorkbook.Worksheets(I).Range("G38")
Next I
MsgBox ("La suma de todo es" & sumatoria&)
End Sub

Quiero que me sume todas las celdas del numero de hojas que tiene mi libro y después me lo despliegue en un mensaje...

1 Respuesta

Respuesta
1

¿Esto es Visual Basic o macros de Excel?

Me parece que es excel, deme un momento y le genero la solución.

Sub diario()
Dim WS_Count As Integer
Dim I As Integer
Dim fecha_buscar As String

WS_Count = ActiveWorkbook.Worksheets.Count
fecha_buscar = InputBox("que fecha?, te recuerdo que es DD-MM-AA")
sumatoria = 0
For I = 1 To WS_Count
If fecha_buscar = ActiveWorkbook.Worksheets(I).Range("G8").Value Then
sub_sumatoria = ActiveWorkbook.Worksheets(I).Range("G38").Value
sumatoria = sub_sumatoria + sumatoria
End If
Next I
MsgBox ("La suma de todo es " & sumatoria)
End Sub

El primer error es no haber declarado la variable fecha_buscar como string

El segundo error es no haber colocado el End If

El tercer error fue colocar la asignación de fecha buscar dentro del bucle For

Sub diario()

Dim WS_Count As Integer
Dim I As Integer
Dim fecha_buscar As String

WS_Count = ActiveWorkbook.Worksheets.Count
fecha_buscar = InputBox("que fecha?, te recuerdo que es DD-MM-AA")
sumatoria = 0

For I = 1 To WS_Count
If fecha_buscar = ActiveWorkbook.Worksheets(I).Range("G8").Value Then
sub_sumatoria = ActiveWorkbook.Worksheets(I).Range("G38").Value
sumatoria = sub_sumatoria + sumatoria
End If
Next I
MsgBox ("La suma de todo es " & sumatoria)

End Sub

Revisa y me comentas

Amigo. el fin de semana me la pase dándole y me quedo muy igual a la tuya pero mira al final no me sumatorea nada, me aparece en CERO. mira..

http://www.subeimagenes.com/img/excel-936435.html

Lo mas probable es que no hayas declarado la variable fecha_buscar como String "Dim fecha_buscar As String".

Prueba con mi solución y veras que te funciona.

Ya la declare, ya copie tu código y me sigue saliendo en "CERO" si quieres te paso mi archivo para que lo veas !! :) solo pásame tu correo por favor. gracias por tu tiempo y dedicación...

así quedo al final brincandome la principal que no quiere que me sume pues no esta dentro de los folios ... si no es la generadora de folios...

Sub diario()
Dim WS_Count As Integer
Dim I As Integer
Dim fecha_buscar As String
WS_Count = ActiveWorkbook.Worksheets.Count
fecha_buscar = InputBox("que fecha?, te recuerdo que es DD-MM-AAAA")
sumatoria = 0
For I = 1 To WS_Count
If fecha_buscar = ActiveWorkbook.Worksheets(I).Range("G8").Value Then
sub_sumatoria = ActiveWorkbook.Worksheets(I).Range("G38").Value
sumatoria = sumatoria + sub_sumatoria
End If
Next I
sumatoria = sumatoria - ActiveWorkbook.Worksheets("GENERAL").Range("G38").Value
MsgBox ("La suma de todo es " & sumatoria)
End Sub

Gracias amigo, pero seria mucha molestia algo para agregar los folios que sumo?

Sub diario()
Dim WS_Count As Integer
Dim I As Integer
Dim fecha_buscar As String

Dim folios As String

WS_Count = ActiveWorkbook.Worksheets.Count
fecha_buscar = InputBox("que fecha?, te recuerdo que es DD-MM-AAAA")
sumatoria = 0
folios = ""
For I = 1 To WS_Count
If fecha_buscar = ActiveWorkbook.Worksheets(I).Range("G8").Value Then
sub_sumatoria = ActiveWorkbook.Worksheets(I).Range("G38").Value
sumatoria = sumatoria + sub_sumatoria

folios = folios & ActiveWorkbook.Worksheets(I).Name & " "

End If
Next I

MsgBox ("La suma de todo es " & sumatoria & " | Folios: " & folios)

End Sub

Excelente bro, fue de lo mejor la solución... aunque podríamos quitarle la primera hoja ( GENERAL ) para que no aparezca estoy intentando pero no me deja hahahahaha

Seguiré intentando...

Cambia de intentar la fecha en la primera hoja, la idea es que la macro no la encuentre en la primera hoja.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas