0

I am trying to run this code:

Private Sub CommandButton1_Click()

Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer, cellValue1 As String

myFile = "c:\h\sales.TXT"
Set rng = Selection

Open myFile For Output As #1

For i = 1 To rng.Rows.Count
    cellValue1 = rng.Cells(i, 1).Value
    Write #1 "INSERT INTO JLPT COL1,COL2 VALUES ('" & cellValue1 & "')"
Next i

Close #1

End Sub

But it gives me a compile error with no more details on the line with Write.

Can someone give me some advice on this?

3
  • 2
    you are missing the comma after Write #1, modify to Write #1, "INSERT INTO JLPT COL1,COL2 VALUES ('" & cellValue1 & "')" Commented Aug 28, 2016 at 3:33
  • @ShaiRado - Can you add this as an answer so I can accept. Thank you Commented Aug 28, 2016 at 4:17
  • sure, see answer below Commented Aug 28, 2016 at 5:01

1 Answer 1

1

you are missing a comma, replace your line :

Write #1 "INSERT INTO JLPT COL1,COL2 VALUES ('" & cellValue1 & "')"

With:

Write #1, "INSERT INTO JLPT COL1,COL2 VALUES ('" & cellValue1 & "')"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.