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
Below is my 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
.Range(.Cells(i, j)).Value = str
Next j
Next i
Print #2, str
End With
Close #2
End Sub
Highlighted line is the 1004 error. Please help to solve and store in a variable in Notepad.
Thanks in advance!
.Cells(i, j).Value = strstr, so need to flip the sides of that assignment:str = .Cells(i, j).ValuePrintline within your innerFor jloop, or else you'll only ever print out the last value.