title: Using a date variable in VBA macro?
body: <p>I am trying to use a date variable within a macro, where I have a date as input and I want to calculate the number of the day for it. Here is a piece of code:</p>
  
  <pre><code>Dim ntf as Date
  
  
  '#An example of ntf is "12/10/2006  15:17:09" (properly formatted as a date)   
  Sheets("myshhet").Select
  ntf = Cells(2, 4)
  Cells(6, 6).FormulaR1C1 = "=WEEKDAY(" &amp; ntf &amp; ")"
  </code></pre>
  
  <p>but it gives me error </p>
  
  <blockquote>
    <p>run-time error '1004'</p>
  </blockquote>
  
  <p>at line in which appears the formula).</p>
  
  <p>Instead, if I use:</p>
  
  <pre><code>Dim ntf as Long
  </code></pre>
  
  <p>it works but it gives a wrong result.</p>
  
  <p>What am I doing wrong?</p>