Changes done, it gives compiling error on line of Next C, error is
"Next without For"
Here is ref code.
---------------
Sub MakeCSV()
Dim fs As Object, a As Object, y As Object, C As Integer, i As Integer, r As Integer, S As String, t As Variant, CellValue As String
'Create a file object for writing
Set fs = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
MkDir ("C:\RT") 'This will create a folder RT in C Drive.
FileName = "C:\RT\MyCSVMS.txt" 'This file is used to write quotes
Set a = fs.CreateTextFile(FileName, True) 'Here we create the file MyCSV.csv
If NSENOW = "Yes" Then
a.writeline "TICKER,PER,DATE,TIME,OPEN,HIGH,LOW,CLOSE,VOLUME,OPEN INTEREST"
MyBook.Sheets("Now").Select 'Selects sheet containing quotations
For r = 7 To Range("A65536").End(xlUp).Row
S = ""
For C = 1 To 5
While Not IsEmpty(Cells(r, C))
If C = 1 Then
CellValue = Cells(r, C).Value & Left(Cells(r, 6).Value, 1) & Cells(r, 7).Value & ",I," & Format$(Date, "yyyymmdd") ' ' (Insert first letter of Option Type, Strike Price, comma and I and Date after ticker name)
ElseIf C = 3 Then 'Insert Last Traded Price 4 times for O,H,L,C
CellValue = Cells(r, C).Value & "," & Cells(r, C).Value & "," & Cells(r, C).Value & "," & Cells(r, C).Value
ElseIf C = 4 Then
CellValue = Cells(r, C).Value - Vol(r, 1)
Vol(r, 1) = Cells(r, C).Value
' Debug.Print Cells(r, 1).Value & " - " & CellValue & " - " & Vol(r, 1)
Else
CellValue = Cells(r, C).Value '
End If
' CellValue = Cells(r, C).Value '
S = S & CellValue & "," 'Add contents of current cell to string 's' and a comma
Next C
Wend
a.writeline S 'write line
Next r
End If
-----------
"Next without For"
Here is ref code.
---------------
Sub MakeCSV()
Dim fs As Object, a As Object, y As Object, C As Integer, i As Integer, r As Integer, S As String, t As Variant, CellValue As String
'Create a file object for writing
Set fs = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
MkDir ("C:\RT") 'This will create a folder RT in C Drive.
FileName = "C:\RT\MyCSVMS.txt" 'This file is used to write quotes
Set a = fs.CreateTextFile(FileName, True) 'Here we create the file MyCSV.csv
If NSENOW = "Yes" Then
a.writeline "TICKER,PER,DATE,TIME,OPEN,HIGH,LOW,CLOSE,VOLUME,OPEN INTEREST"
MyBook.Sheets("Now").Select 'Selects sheet containing quotations
For r = 7 To Range("A65536").End(xlUp).Row
S = ""
For C = 1 To 5
While Not IsEmpty(Cells(r, C))
If C = 1 Then
CellValue = Cells(r, C).Value & Left(Cells(r, 6).Value, 1) & Cells(r, 7).Value & ",I," & Format$(Date, "yyyymmdd") ' ' (Insert first letter of Option Type, Strike Price, comma and I and Date after ticker name)
ElseIf C = 3 Then 'Insert Last Traded Price 4 times for O,H,L,C
CellValue = Cells(r, C).Value & "," & Cells(r, C).Value & "," & Cells(r, C).Value & "," & Cells(r, C).Value
ElseIf C = 4 Then
CellValue = Cells(r, C).Value - Vol(r, 1)
Vol(r, 1) = Cells(r, C).Value
' Debug.Print Cells(r, 1).Value & " - " & CellValue & " - " & Vol(r, 1)
Else
CellValue = Cells(r, C).Value '
End If
' CellValue = Cells(r, C).Value '
S = S & CellValue & "," 'Add contents of current cell to string 's' and a comma
Next C
Wend
a.writeline S 'write line
Next r
End If
-----------
Last edited: