title: Using VBA, Not able to store the cell value in a variable and throws 1004 error
body: <p>I am in learning phase in vba. I am trying to store a value in a variable but not able do with Cell and also Range and it throws an 1004 error</p>
  
  <p>Below is my code</p>
  
  <pre><code>Sub myself()
  
  Dim str As String
  Dim rock As String
  Dim MaxStrLen As Integer
  Dim StrLen As String
  Dim LastRow As Long
  Dim LastCol As Long
  Dim ws1 As Worksheet
  Dim ws2 As Worksheet
  Dim i As Integer
  Dim j As Integer
  
  Dim FilePath As String
  
  Set ws1 = Sheets("Sheet1")
  Set ws2 = Sheets("Sheet2")
  
  LastRow = Cells(Rows.Count, 1).End(xlUp).Row
  LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
  
  Open "C:\Users\Antony\Desktop\test.txt" For Output As #2
  
  ws1.Activate
  
  With ws1
  For i = 0 To LastRow
  For j = 0 To LastCol
  </code></pre>
  
  <p><strong>.Range(.Cells(i, j)).Value = str</strong></p>
  
  <pre><code>Next j
  
  Next i
  
  Print #2, str
  End With
  
  Close #2
  
  End Sub
  </code></pre>
  
  <p>Highlighted line is the 1004 error. Please help to solve and store in a variable in Notepad.</p>
  
  <p>Thanks in advance!</p>