tensionalvolt
New Member
- Joined
- Oct 11, 2017
- Messages
- 11
Hi guys,
First time posting to a thread like this so apologies if I ask this query in a convoluted manner.
That said, I am currently writing a macro for appending the range of an active worksheet to a .txt file
for further analysis. Whilst I have successfully written this for a test excel file, the worksheet I wish to have
this macro operate on contains NA() values within cells of the range I want to append. Subsequently, I receive
a 2042 error. I have tried implementing a way around this through use of the ISNA function but to no avail.
Here is a copy of the macro as it currently stands...
Feel free to change the range and manually enter an NA() function for testing purposes. I will post my progress to this forum for future benefits. Hopefully we can resolve this together
All the best,
Tension
First time posting to a thread like this so apologies if I ask this query in a convoluted manner.
That said, I am currently writing a macro for appending the range of an active worksheet to a .txt file
for further analysis. Whilst I have successfully written this for a test excel file, the worksheet I wish to have
this macro operate on contains NA() values within cells of the range I want to append. Subsequently, I receive
a 2042 error. I have tried implementing a way around this through use of the ISNA function but to no avail.
Here is a copy of the macro as it currently stands...
Code:
Sub AutoCollect()
'
' AutoCollect1 Macro
' Ideally appends data to a larger file for more stochastically valid data acquisition.
'
Dim filename As String, lineText As String
Dim myrng As Range, i, j
filename = ThisWorkbook.Path & "\AC" & ".txt"
Open filename For Append As #1
' Make sure to set range appropriately for your data acquisition
Set myrng = Range("Z794:AZ1426")
For i = 1 To myrng.Rows.Count
For j = 1 To myrng.Columns.Count
lineText = IIf(j = 1, "", lineText & " ") & myrng.IF(Application.WorksheetFunction.NOT(Application.WorksheetFunction.IsNA(Cells(i, j))), "N/a", Cells(i,j))
Next j
Print #1 , lineText
Next i
Close #1
Application.Calculate
MsgBox ("Done")
End Sub
Feel free to change the range and manually enter an NA() function for testing purposes. I will post my progress to this forum for future benefits. Hopefully we can resolve this together
All the best,
Tension
Last edited by a moderator: