title: How do you autofill dates in a column when a date is imported from another sheet by button press weekly?
body: <p>I am attempting to write a code in VBA to copy weekly comments and the date that the week begins on from one sheet (ws1) to a second one for storage (ws4), auto-populate the remaining dates for the week, and finally add a new line to the bottom of the sheet.</p>
  
  <p>I can get the program to copy the comments and the date from ws1 to ws4. They go into their appropriate columns as they should.<br>
  If I press it a second time however, it just overwrites my data and adds a date below the entered date. That's why I figure if I add the dates all the way through, that will solve that issue.<br>
  My problem at present is that I can't get the code (I believe should work) to auto-populate my dates. When I get to that line in my code, I am presented with the following error:<br>
  "Run-Time Error '1004':<br>
  Application-defined or object defined error"<br>
  I have looked to try and figure out what it is exactly that is going on and despite my research and hunting, I can't seem to get it to work. I don't know if I'm trying to call out something incorrectly, or if what I'm doing is just not possible.</p>
  
  <p>I considered using an 'If/ Then/ Else' argument to get things to work but I couldn't get it to play nice. The link to the page I looked at to try and figure that out is <a href="https://stackoverflow.com/questions/31374025/if-then-statement-in-vba-to-fill-cell-with-number">here</a>.<br>
  I then thought about that <a href="https://stackoverflow.com/questions/37809881/autofill-a-column-with-month-name-depending-on-the-date-in-another-column-exce">this</a> post may provide a bit more insight since it was similar to what I was trying to do regarding entering a month based on another entered date (almost literally my problem). However, this option didn't work for me either. 
  Lastly I got to my current solution (which seemed simple and easy to make work). <a href="https://stackoverflow.com/questions/41098031/excel-vba-date-until-last-row">Here</a> is the link to that original solution with my changed reflected in my provided code.</p>
  
  <p>I'm at a loss as to what is happening and where to go from here. Below you will see my shortened portion of code for this part specifically (it's part of a bigger code that works minus this bit).</p>
  
  <pre><code>Private Sub CommandButton2_Click()
  
  Dim ws1 As Worksheet: Set ws1 = Sheets("Weekly Job Progress")
  Dim ws4 As Worksheet: Set ws4 = Sheets("Comment Storage")
  Dim lrow2 As Long: lrow2 = ws4.Cells(Rows.Count, 1).End(xlUp).Row + 1
  
  With ws1 
      'Copy the date to &amp; from.
      ws4.Cells(lrow2, 1) = .Range("E3")
      For m = 7 To 13
          n = m - 4
          'Copy the days of the week
          ws4.Cells(n, 2) = .Range("I" &amp; m)
          'Copy the comments entered
          ws4.Cells(n, 3) = .Range("K" &amp; m)
      Next 
  End With
  
  With ws4 
      rowf = .Cells(Rows.Count, 1).End(xlUp).Row
      'Supposed to automatically populate the dates on ws4 up to the last row... Doesn't work.
      .Range("B:B" &amp; rowf).Value = (rowf - 1)
      'Supposed to add a new row at the bottom of my sheet but doesn't (no clue why because the same code works on ws3 [not shown].)
      .Range("A" &amp; lrow2 + 1).EntireRow.Insert
  End With
  
  End Sub
  </code></pre>
  
  <p>If I have done something wrong in my posting of this, please let me know as this is my first time posting to this website though I have used it for my research and learning a good bit in the past couple of weeks.<br>
  Thank you.</p>
  
  <p><strong>Edit 1:</strong> Cleaned up the code and noted it to hopefully make it easier to understand what I'm trying to do and where my problems are. I also made the change that was mentioned in the comments about not using reference with the same letter as a column. Otherwise, my code is unchanged.</p>