+ Reply to Thread
Results 1 to 9 of 9

Removing Quotation from text. (Using EOF)

  1. #1
    Registered User
    Join Date
    10-15-2012
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    13

    Removing Quotation from text. (Using EOF)

    Hey guys. I am trying to write .txt into excel using VBA.

    This is something I got from the internet. I've attached the text file.

    I am trying to select the first couple of lines which has quotation around them. What can I do to select the lines with quotation and remove them. At the same time, leaving the numeric data lines written on excel.

    Thank you.

    Public Sub textToexcel()
    Dim FilePath As String
    Dim strLine As String
    Dim i As Integer

    Dim lines As Collection
    Set lines = New Collection

    FilePath = "C:\Users\Deepsheit\Desktop\School\lab 5\singleSpecimen.txt"
    Open FilePath For Input As #1

    If Err <> 0 Then
    MsgBox "Not found: " & Filename, vbCritical, "ERROR-GDS"
    Exit Sub
    End If
    i = 1
    While EOF(1) = False
    Line Input #1, strLine
    Cells(i, 1) = strLine
    i = i + 1

    Wend



    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Removing Quotation from text. (Using EOF)

    How about ...

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-15-2012
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Removing Quotation from text. (Using EOF)

    Thanks for the reply shg. Maybe I was not clear with my question.

    As I run the above code in the macro, it writes the info. from text to excel. However, they show the quotation for the first 5 lines which are

    ""
    "Test Method" "TENSILE MASTER"
    "Sample I. D." "OSB"
    "Specimen Number "1"

    "EXTENSION (In)"" LOAD (Lb)"

    I think I am suppose to use replace() function and extractelement() function... Is there a way I could select only those lines with quotation and remove them?

    leaving the data lines the way it is...

    Thanks.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Removing Quotation from text. (Using EOF)

    What do you see when you run the code I posted that isn't what you want? I don't see any quotation marks.

  5. #5
    Registered User
    Join Date
    10-15-2012
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Removing Quotation from text. (Using EOF)

    Oh shoot, my bad there is supposed to be quotation in the .txt file that i attached.

    This new attached .txt contains the file with quotations around the first couple of lines.

    Thanks.
    Attached Files Attached Files

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Removing Quotation from text. (Using EOF)

    Please Login or Register  to view this content.
    Last edited by shg; 02-11-2015 at 01:49 AM.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Removing Quotation from text. (Using EOF)

    Do you mean like this?
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-15-2012
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Removing Quotation from text. (Using EOF)

    YES! IT WORKED.

    Thank you so much shg and jindon i really appreciate your help!

    SHG, I have another question regarding "Const sFile", "If Len(Dir(sFile)) Then" and, " Cells.Replace What:=Chr(34), Replacement:="", LookAt:=xlPart"

    I get how "Len" works since it returns the length of the string and "Dir" is calling the specific filename...

    However, what does the "Const" do?

    Also, for "" Cells.Replace What:=Chr(34), Replacement:="", LookAt:=xlPart""

    This function basically replaces Chr(34) (quotation) with empty spaces if I am correct?

    Thanks.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Removing Quotation from text. (Using EOF)

    1. Const declares a value as a constant, a value that is defined at compile time and cannot change at run time. The expression may use nothing but constants, operators, and arithmetic.

    2. It deletes quotation marks, yes.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Removing double quotation marks from numeric data.
    By Bill Cameron in forum Excel General
    Replies: 1
    Last Post: 03-08-2014, 11:38 AM
  2. Single quotation and VBA pasting as text.
    By mhamlon in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-23-2013, 06:15 AM
  3. Replies: 3
    Last Post: 07-29-2013, 08:55 AM
  4. [SOLVED] Removing quotation marks in a txt-file
    By Reedhill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2006, 03:20 PM
  5. joining text and quotation mark
    By yakuzza in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-11-2005, 08:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1