Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1020153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:07:22+00:00 2026-05-16T11:07:22+00:00

I am reading a text file line by line with VBA into a worksheet.

  • 0

alt text

I am reading a text file line by line with VBA into a worksheet. it’s often returning these characters. Does anyone know how to remove them?

this is how i am reading it:

Sub ReadAsciiFile()

    Dim sFileName As String
    Dim iFileNum As Integer
    Dim sBuf As String
    Dim i As Integer
    i = 1

    ' edit this:
    sFileName = "usmap.txt"

    ' does the file exist?  simpleminded test:
    If Len(Dir$(sFileName)) = 0 Then
        Exit Sub
    End If

    iFileNum = FreeFile()
    Open sFileName For Input As iFileNum

    Do While Not EOF(iFileNum)
        Line Input #iFileNum, sBuf
        ' now you have the next line of the file in sBuf
        ' do something useful:
        activesheet.Cells(i, 1) = sBuf
        i = i + 1
        Debug.Print sBuf
    Loop

    ' close the file
    Close iFileNum

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:07:22+00:00Added an answer on May 16, 2026 at 11:07 am

    First, if you’re copying and pasting into Excel, check your paste method and try “Paste Special” as Text (as opposed to HTML or Unicode Text).

    You can also use a simple VBA function to find out what the invalid characters are. Then you could either use another VBA function to remove the invalid characters or use the Excel formula Substitute() function which I showed in the last question you asked. Here’s a quick example of some VBA code to see what characters exist in cell A1:

    Sub PrintChars()
      Dim intLen As Integer
      Dim str As String
      str = Range("A1").Value
      intLen = Len(str)
      Dim intCount As Integer
      intCount = 1
    
      Dim strChar As String
    
      Do While intCount <= intLen
        strChar = Mid(str, intCount, 1)
        Debug.Print strChar & ": " & Asc(strChar)
        intCount = intCount + 1
      Loop
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading a text file line by line, and storing it into a NSArray.
I am reading a text file which I know its 38th line is Uncalibrated
I'm reading a text file line by line and converting it into a string.
Anyone got anything about reading a sequential number from text file per line and
I am reading a text file line by line in C++. I'm using this
Here I'm reading text file which contains a integer in each line and I'm
I am reading from a text file line by line. StreamReader reader = new
I am reading a text file into Matlab called 'test.txt' which is structured as
Possible Duplicate: Reading from text file until EOF repeats last line c++ EOF running
I am trying to replace text in a text file by reading each line,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.