VBA Insertar fecha como numero en hoja desde un label o textbox
buenas, he intentado insertar fechas desde un label o un textbox de un formulario en una hoja pero en forma de numero por ejemplo
textbox o label: 12/12/2012
celda:40234
intente con formatnumber incluso con la grabadora de macros y nada
la razón es porque necesito una columna con las fechas convertidas en números para realizar formulas que me están generando errores como: N/A o nombre?
el formulario ingresa datos nuevos a la base de datos cosa que me funciona bien aunque algo lento, la cual es esta
Public Sub Datos() 'On Error Resume Next Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Application.EnableEvents = False ActiveSheet.DisplayPageBreaks = False ActiveSheet.Unprotect "entrar" For i = 1 To ReCantidad Step 1 Range("B7").Select Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select Loop ActiveSheet.Unprotect "entrar" With Rows(ActiveCell.Row) .Font.Size = 10 .Font.Name = "Tahoma" .RowHeight = 13 End With ActiveCell = CDbl(ReCodigo) ActiveCell.Font.Bold = True ActiveCell.Offset(0, 1) = ReCategoria If IsNumeric(ReFactura) Then ActiveCell.Offset(0, 2) = CDbl(ReFactura) Else ActiveCell.Offset(0, 2) = ReFactura End If ActiveCell.Offset(0, 3).FormulaR1C1 = "=SUMPRODUCT(1*(R7C4:R65536C4=RC4))" ActiveCell.Offset(0, 4).FormulaR1C1 = Evaluate("=ROW()-7") If ReReferencia.Visible = False Then ActiveCell.Offset(0, 5) = "" Else ActiveCell.Offset(0, 5) = CDbl(ReReferencia) End If ActiveCell.Offset(0, 6) = ReDescripcion ActiveCell.Offset(0, 7) = ReEstado ActiveCell.Offset(0, 8) = ReFecha ActiveCell.Offset(0, 9) = Date ActiveCell.Offset(0, 11) = CDbl(ReVaUnitario) ActiveCell.Offset(0, 11).Font.Bold = True ActiveCell.Offset(0, 12).FormulaR1C1 = "=SUMPRODUCT((R7C4:R65536C4=RC4)*R7C13:R65536C13)" ActiveCell.Offset(0, 12).Font.Bold = True ActiveCell.Offset(0, 13).FormulaR1C1 = "=IF(RC17=0,0,DATEDIF(RC10,R4C35+1,""Y""))" ActiveCell.Offset(0, 14).FormulaR1C1 = "=IF(RC17=0,0,DATEDIF(RC10,R4C35+1,""YM""))" ActiveCell.Offset(0, 15).FormulaR1C1 = "=IF(DAYS360(RC10,R4C35)<0,0,DAYS360(RC10,R4C35))" ActiveCell.Offset(0, 16).FormulaR1C1 = "=IF(DED(RC2)<RC17,RC13,DACUM(RC13,DEP(RC2),RC17))" ActiveCell.Offset(0, 17).FormulaR1C1 = "=IF(DED(RC2)<RC17,0,IF(RC17=0,0,IF(RC17<30,DACUM(RC13,DEP(RC2),RC17),IF(DED(RC2)-RC17>=30,DMEN(RC13,DEP(RC2)),IF(DED(RC2)-RC17=0,0,DACUM(RC13,DEP(RC2),DED(RC2)-RC17))))))" ActiveCell.Offset(0, 18).FormulaR1C1 = "=IF(DED(RC2)<RC17,0,IF(RC17=0,0,IF(RC17<360,DACUM(RC13,DEP(RC2),RC17),IF(DED(RC2)-RC17>=360,RC13*DEP(RC2),IF(DED(RC2)-RC17=0,0,DACUM(RC13,DEP(RC2),DED(RC2)-RC17))))))" ActiveCell.Offset(0, 19).FormulaR1C1 = "=IF(RC[-3]=0,0,IF(RC[-4]=0,0,RC[-8]-RC[-3]))" ActiveCell.Offset(0, 19).Font.Bold = True ActiveCell.Offset(0, 20).FormulaR1C1 = "=IF(RC[-1]=0,0,IF(RC[-5]=0,0,RC[-8]-DACUM(RC[-8],DEP(RC[-20]),RC[-5])))" ActiveCell.Offset(0, 20).Font.Bold = True 'Datos de año anterior al 30/Diciembre ActiveCell.Offset(0, 23).FormulaR1C1 = "=IF(RC17=0,0,DATEDIF(RC10,R6C35+1,""Y""))" ActiveCell.Offset(0, 24).FormulaR1C1 = "=IF(RC16=0,0,DATEDIF(RC10,R6C35+1,""YM""))" ActiveCell.Offset(0, 25).FormulaR1C1 = "=IF(DAYS360(RC10,R6C35)<0,0,DAYS360(RC10,R6C35))" ActiveCell.Offset(0, 26).FormulaR1C1 = "=IF(DED(RC2)<RC[-1],0,DACUM(RC13,DEP(RC2),RC[-1]))" ActiveCell.Offset(0, 27).FormulaR1C1 = "=IF(DED(RC2)<RC[-2],0,IF(RC[-2]=0,0,IF(RC[-2]<30,DACUM(RC13,DEP(RC2),RC[-2]),IF(DED(RC2)-RC[-2]>=30,DMEN(RC13,DEP(RC2)),IF(DED(RC2)-RC[-2]=0,0,DACUM(RC13,DEP(RC2),DED(RC2)-RC[-2]))))))" ActiveCell.Offset(0, 28).FormulaR1C1 = "=IF(DED(RC2)<RC[-3],0,IF(RC[-3]=0,0,IF(RC[-3]<360,DACUM(RC13,DEP(RC2),RC[-3]),IF(DED(RC2)-RC[-3]>=360,RC13*DEP(RC2),IF(DED(RC2)-RC[-3]=0,0,DACUM(RC13,DEP(RC2),DED(RC2)-RC[-3]))))))" ActiveCell.Offset(0, 29).FormulaR1C1 = "=IF(RC[-3]=0,0,IF(RC[-4]=0,0,RC13-RC[-3]))" ActiveCell.Offset(0, 30).FormulaR1C1 = "=IF(RC[-4]=0,0,IF(RC[-5]=0,0,RC14-DACUM(RC14,DEP(RC2),RC[-5])))" ultima = Range("F900000").End(xlUp).Row Range("B" & ultima & ":V" & ultima).Select PintaBerde Range("M" & ultima & ":N" & ultima).Select PintaRellTotal Range("O" & ultima & ":T" & ultima).Select PintaBanja Range("U" & ultima & ":V" & ultima).Select PintaRellTotal Next i Range("B6:V6").BorderAround LineStyle:=xlContinuous ActiveSheet.Unprotect "entrar" Application.ScreenUpdating = True Application.Calculation = xlCalculationAutomatic Application.EnableEvents = True ActiveSheet.DisplayPageBreaks = True Application.CutCopyMode = False End Sub
la columna estará oculta a partir de la 22 por eso que el código debe entrar a esta
ActiveCell.Offset(0, 22) = ReFecha
ReFecha es el nombre del label
uso excel 2007/2010
espero haber detallado bien la duda
1 Respuesta
Respuesta de Elsa Matilde
1