0

I am trying to write cells E3:E16 of a specific sheet to a CSV (or TXT for that matter) upon opening of the excel document.

Private Sub Workbook_Open()

Open "W:\Folder\Folder\Folder\locations.csv" For Output As #1
    For cCount = 3 To 16
        Print #1, Range("E" + cCount)
    Next cCount
Close #1
End Sub

I am getting Runtime Error 13 Type Mismatch.

Is a For loop the way to go in VBA? This is my first time ever using it and am used to python and Java.

sameh
  • 1
  • 1
    `+` should be `&`. – BigBen Dec 21 '21 at 16:31
  • 1
    To make sure that the range is from the specific sheet that you want, I suggest adding the Parent Objects to the statement like `ThisWorkbook.Sheets("Name").Range(...` Or you can use the VB Project "Codename" of the sheet like `Sheet1.Range(...` – Toddleson Dec 21 '21 at 17:07

0 Answers0