¿Cómo automatizar este código de fechas?

ColdGeorge

Active Member
Joined
Aug 21, 2012
Messages
407
Office Version
  1. 2016
Platform
  1. Windows
Buenos días
Estoy ocupado en un registro de visitas, en la hoja "registro" B2 se muestra la fecha del día. En B4:B15 se enlistan los meses. En C4:C15 se suman las visitas al archivo conforme al mes. ¿Cómo puedo hacer que al cambiar el mes y el número del mes sea diferente las visitas vayan al lugar correspondiente? Gracias de antemano por su ayuda.

VBA Code:
Private Sub Workbook_Open()
Dim numfechados As Integer
Worksheets("registro").Range("B2").Value = Date
numfechados = Month(Worksheets("registro").Range("B2").Value)
If numfechados = 6 Then 'cambiar número al cambiar el mes
    Worksheets("registro").Range("C9").Value = Worksheets("registro").Range("C9").Value + 1 'cambiar rango según el mes
End If
End Sub

ColdGeorge
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hola.
Prueba lo siguiente:

VBA Code:
Private Sub Workbook_Open()
  Dim num As Integer
  With Sheets("registro")
    .Range("B2").Value = Date
    num = Month(Date)
    .Range("C" & num + 3).Value = .Range("C" & num + 3).Value + 1
  End With
End Sub
 
Upvote 0
Hola Dante

Tu código no funcionó en absoluto, hice pruebas y ninguna dio los resultados que busco. Agradezco tu intención de ayudar, sin embargo, opté por el uso de Select Case. Y los resultados son buenos. Saludos a tu tierra.

ColdGeorge
 
Upvote 0
Tienes que poner el código en los eventos del libro.
Cada que abras el libro, se ejecuta la macro.
También debes tener una hoja llamada "registro"
Incluso puedes ejecutar la macro sin cerrar-abrir el libro.

Y por supuesto, no debes modificar la macro.

Si no te funciona, sería bueno que compartieras tu macro con todos.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,044
Members
448,543
Latest member
MartinLarkin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top