csv file opened in notepad has extra row

o1darcie1o

New Member
Joined
May 12, 2017
Messages
1
A csv file created in excel is giving an error message when trying to upload into another program. The error message indicates an extra blank row at the end of the file.

I created a csv file in excel.
If I open it in excel and press control+end, the active cell moves to the last cell with data.
If I open it in notepad and press control+end, the cursor moves to the first blank row after the data.
In notepad, I can press backspace, save and close the file, and when I reopen it in notepad and press control+end, the cursor correctly goes to the right of the last character in the file.

This csv file is created via a macro, and I don't want the end user to have to manually open the file in notepad, backspace, save, then upload into the system. I'd like them to be able to have their excel file open, run the macro, then switch to the system and upload the file created by the macro.

Any suggestions on how to accomplish this?

Thanks!!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi there

I had this issue a while ago and found some code on a microsoft blog (technet I think) which I hacked around for my purposes (unfortunately can't remember where exactly so cant give proper credit to the author, but here it is anyway:

Code:
Sub striplast()

Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\development\test.csv", ForReading)
strFile = objFile.ReadAll
objFile.Close
intLength = Len(strFile)
strEnd = Right(strFile, 2)
If strEnd = vbCrLf Then
    strFile = Left(strFile, intLength - 2)
    Set objFile = objFSO.OpenTextFile("C:\development\test.csv", ForWriting)
    objFile.Write strFile
    objFile.Close
End If

End Sub

Just replace the 2 occurences of 'C:\development\test.csv' with your pathname.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top