Reputation: 11
just started learning VBA and in one of my lesson I get to work with dates. I wrote the following code:
Sub Aula11 ()
Dim data1 as date
Dim data2 as date
Dim diferençadatas as long
Data1 = Date
Data2 = #2/8/2018#
diferençadatas = data1 – data2
MsgBox = “Passaram” & diferençadatas & “dias desde o dia 8 de Fevereiro de 2018”
End Sub
When I hit run, I get the following message: "Compile error: Function call on left-hand side of assignement must return Variant or Object" on subroutine line (line 1).
I don't understand what's wrong, I used date functions before and the first line was the same. Sorry about my dumb question, just trying to learn something so differently from what I'm used to :D
Upvotes: 0
Views: 120
Reputation: 43585
As you are a learner, consider not using variable names with letters deviating from the 26 standard letters of the English alphabet. Thus, diferencadatas
could become easily diferençadatas
.
As a second best practice - please name the variables in English. Thus a colleague who does not speak Portuguese can also take over your code easily.
This works quite ok:
Sub Aula11()
Dim data1 As Date
Dim data2 As Date
Dim diferencadatas As Long
data1 = Date
data2 = #2/8/2018#
diferencadatas = data1 - data2
MsgBox ("Passaram" & diferencadatas & "dias desde o dia 8 Fevereiro de 2018")
End Sub
Upvotes: 1