Ajustar esta macro a los parámetros nuevos
Tengo esta maro:
Private Sub Worksheet_Activate()
'Por.Dante Amor
ActiveSheet.Unprotect Password:="1"
Application.EnableEvents = False
Set h = Sheets("Diario Venta")
'limpiar colores
h.Range("D4:AH15").Interior.ColorIndex = xlNone
h.Range("D4:AH15").Font.ColorIndex = xlAutomatic
mes = Format(Date, "mmmm")
dia = Day(Date)
Set b = h.Range("C4:C15").Find(mes, LookAt:=xlWhole)
If Not b Is Nothing Then
f = b.Row
Set b = h.Range("D2:AH2").Find(dia, LookAt:=xlWhole)
If Not b Is Nothing Then
C = b.Column
For i = 4 To f
For J = 4 To 34
If i = f And J = C Then
Exit For
End If
conta = conta + h.Cells(i, J)
Next
Next
ventatotal = h.[A4]
h.Cells(f, C) = ventatotal - conta
h.Cells(f, C).Interior.ColorIndex = 28
h.Cells(f, C).Font.ColorIndex = 1
End If
End If
Application.EnableEvents = True
End Sub
Y la he rectificado así:
Private Sub Worksheet_Activate()
'ActiveSheet.ScrollArea = "A:S"
'Por.Dante Amor
ActiveSheet.Unprotect Password:="1"
Application.EnableEvents = False
Set h = Sheets("Diario Venta")
'limpiar colores
h.Range("D5:S28").Interior.ColorIndex = xlNone
h.Range("D5:S28").Font.ColorIndex = xlAutomatic
mes = Format(Date, "mmmm")
dia = Day(Date)
Set b = h.Range("C5:C28").Find(mes, LookAt:=xlWhole)
If Not b Is Nothing Then
f = b.Row
Set b = h.Range("D2:AH2").Find(dia, LookAt:=xlWhole)
If Not b Is Nothing Then
C = b.Column
For i = 4 To f
For J = 4 To 34
If i = f And J = C Then
Exit For
End If
conta = conta + h.Cells(i, J)
Next
Next
ventatotal = h.[A5]
h.Cells(f, C) = ventatotal - conta
h.Cells(f, C).Interior.ColorIndex = 28
h.Cells(f, C).Font.ColorIndex = 1
End If
End If
Application.EnableEvents = True
End Sub
Y no se actualizar esta parte de la macro, al haber cambiado los rangos:
If Not b Is Nothing Then
C = b.Column
For i = 4 To f
For J = 4 To 34
If i = f And J = C Then
Exit For
End If
conta = conta + h.Cells(i, J)
Next
Next
Y lo que me hace, es escribir fuera del rango:
Range("D5:S28")