PDA

View Full Version : Date function error



pepe90
08-05-2011, 08:41 AM
Hello,
I'm having some problems using the Date function on VB for Excel 2007.
In the following code:
Private Sub aceptar_Click()
Dim fila As Integer
With Sheets("DATOS")
.Cells(fila, 10) = Date
End With
end Sub

It shows an error that marks the Date function and says that doesn't find the proyect or library. So I tested the function on another workbook that says:

Sub fecha()
Cells(1, 2) = Date
End Sub

and it worked just fine. The only difference I see between the code is that the first one is on a UserForm module and references the worksheet. Any idea whats going on?

Kenneth Hobs
08-05-2011, 10:26 AM
IF you step through the code with F8, you will see that you did not assign a value to fila.

pepe90
08-05-2011, 11:46 AM
No, no. I just avoided posting some lines, but actually, before the Date line there is code which print values on the "fila" row.

Kenneth Hobs
08-05-2011, 01:33 PM
All we know is what you tell us by showing us. Another guess is that your sheet DATOS does not exist in the active workbook.

It is considered good practice to set the value property for the object.
Sheets("DATOS") .Cells(fila, 10).Value = Date

pepe90
08-05-2011, 02:15 PM
Making some research, I found that adding the prefix VBA. to the Date function, the problem was solved, but I still have the doubt why just working on another workbook it didn't cause any problem. The workbook where the function doesn't work has xlsm format, could it be the reason?

Aflatoon
08-08-2011, 04:23 AM
You have a missing reference in the file where the problem occurs. If you look under Tools->References in the Visual Basic Editor on the machine where the problem occurs, you will see at least one reference prefixed with 'MISSING:'