+ Reply to Thread
Results 1 to 22 of 22

How to copy text in excel cell in rows between numbers from a text file.

  1. #1
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    How to copy text in excel cell in rows between numbers from a text file.

    How to copy the text in excel cells in rows between numbers from a text file.
    The last line does not have a number. There are thousands of numbers.


    Text in text.txt file Example

    1. How to copy the text in rows
    between numbers from a text file.

    How to copy the text in rows between numbers from a text file.
    How to copy the text in rows between numbers from a text file.

    How to copy the text in rows between numbers from a text file.

    3. How to copy the text in rows between numbers from a text file.

    5. How to copy
    the text in rows
    between numbers
    from a text file
    .
    How to copy the text in rows between numbers from a text file


    Output in the excel sheet will look like:


    1 How to copy the text in rows
    between numbers from a text file.

    How to copy the text in rows between numbers from a text file.
    How to copy the text in rows between numbers from a text file.

    How to copy the text in rows between numbers from a text file.
    3 How to copy the text in rows between numbers from a text file.
    5 How to copy
    the text in rows
    between numbers
    from a text file
    .
    How to copy the text in rows between numbers from a text file
    Last edited by jai0000; 09-01-2022 at 06:58 AM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to copy text in excel cell in rows between numbers from a text file.


    Your code just must detect if a text line starts with a number via the VBA Like operator ...

    For more help don't forget to attach at least a sample source text file and for convenience the expected result workbook.
    Last edited by Marc L; 09-01-2022 at 06:38 AM.

  3. #3
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: How to copy text in excel cell in rows between numbers from a text file.

    I have attached a sample source text file and for convenience the expected result workbook.
    Help.
    Last edited by jai0000; 09-07-2022 at 06:35 AM.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    Thanks for the rep' !

    According to your attachment a VBA demonstration for starters :

    PHP Code: 
    Sub Demo1()
            
    Application.GetOpenFilename("Text Files,*.txt"):  If False Then Exit Sub
            
    [A1].CurrentRegion.Offset(1).Clear
            L
    & = FreeFile
            Open W 
    For Input As #L
            
    Split(Input(LOF(L), #L), vbCrLf)
            
    Close #L
            
    ReDim V(1 To UBound(W), 1)
        For 
    Each X In W
            L 
    Val(X)
            If 
    X Like L ". *" Then R& = R& + 1V(R0) = LV(R1) = Split(X, , 2)(1) Else V(R1) = V(R1) & vbLf X
        Next
        With 
    [A2:B2].Resize(R)
            .
    HorizontalAlignment xlLeft
            
    .Value V
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon ? Add Reputation ? !

  5. #5
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: Try this !

    Thank you very much.
    But if the .txt file is big (10 or 20 MB) I get an issue here: L = Val(X)

    Ps. Error showing L = Val(X) and run time error type mismatch 13

    One more thing is please find the attached txt file and see how is it giving the result.
    I am unable to attach a new file. And if I change the number 5 content to the below text I get a different result:

    5. How to copy text in rows betwen numbers from a text file
    .
    How to copy text in rows betwen numbers from a text file
    81911. How to copy text in rows betwen numbers from a text file
    How to copy text in rows betwen numbers from a text file
    1911. How to copy text in rows betwen numbers from a text file
    How to copy text in rows betwen numbers from a text file
    1911. How to copy text in rows betwen numbers from a text file
    1911. How to copy text in rows betwen numbers from a text file
    Attached Files Attached Files
    Last edited by jai0000; 09-10-2022 at 04:22 AM. Reason: updated to clarify and run time error type mismatch 13

  6. #6
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: Try this !

    Quote Originally Posted by Marc L View Post

    Thanks for the rep' !

    According to your attachment a VBA demonstration for starters :

    PHP Code: 
    Sub Demo1()
            
    Application.GetOpenFilename("Text Files,*.txt"):  If False Then Exit Sub
            
    [A1].CurrentRegion.Offset(1).Clear
            L
    & = FreeFile
            Open W 
    For Input As #L
            
    Split(Input(LOF(L), #L), vbCrLf)
            
    Close #L
            
    ReDim V(1 To UBound(W), 1)
        For 
    Each X In W
            L 
    Val(X)
            If 
    X Like L ". *" Then R& = R& + 1V(R0) = LV(R1) = Split(X, , 2)(1) Else V(R1) = V(R1) & vbLf X
        Next
        With 
    [A2:B2].Resize(R)
            .
    HorizontalAlignment xlLeft
            
    .Value V
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon ? Add Reputation ? !
    Help me. I believe a little modification can solve this.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to copy text in excel cell in rows between numbers from a text file.


    Solve what ? As no issue on my side with your attachments ...

  8. #8
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: How to copy text in excel cell in rows between numbers from a text file.

    If the .txt file is big (10 or 20 MB) I get a problem here: L = Val(X) showing run time error type mismatch 13. I request a solution for this only.
    The file attached here is a demo file sir.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to copy text in excel cell in rows between numbers from a text file.


    As guessing can't be coding so you must at least check the variable X content when the error raises ...

  10. #10
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: How to copy text in excel cell in rows between numbers from a text file.

    Quote Originally Posted by Marc L View Post

    As guessing can't be coding so you must at least check the variable X content when the error raises ...
    OK. Sir, is it possible to find, in which line of the text file has an error when I run the VBA?
    I also got Overflow (Error 6).
    Last edited by jai0000; 09-11-2022 at 02:07 PM.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: How to copy text in excel cell in rows between numbers from a text file.


    Now that's just confusing ! And you can check in debug mode when the error raises ...

  12. #12
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: How to copy text in excel cell in rows between numbers from a text file.

    If there are hundreds of lines between numbers then .Value = V gets highlighted in yellow.

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

    Re: How to copy text in excel cell in rows between numbers from a text file.

    See if this works
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: How to copy text in excel cell in rows between numbers from a text file.

    .Resize(UBound(a, 1), 2) = a gets highlighted in yellow.
    Can it be like "Jump to the next number if the current number in the series fails to copy and paste?

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

    Re: How to copy text in excel cell in rows between numbers from a text file.

    Are you testing the code with the text file(s) that you uploaded?

    It is working, so upload the text file that you are working with.

  16. #16
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: How to copy text in excel cell in rows between numbers from a text file.

    can I inbox you the part of the file? I can not share it here. Hope you understand.

    How can I add "56438(*&" before these numbers in my .txt file?
    Last edited by jai0000; 10-10-2022 at 06:22 AM.

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

    Re: How to copy text in excel cell in rows between numbers from a text file.

    Can you not create a mockup dummy data following the structure of your original file?

    If we are dealing with different data, this will never be solved.

    I don't understand the 2nd question.

  18. #18
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: How to copy text in excel cell in rows between numbers from a text file.

    I will make a mock data and will post asp.



    About 2nd question

    From: Text in text.txt file Example:

    1. How to copy the text in rows
    between numbers from a text file.

    How to copy the text in rows between numbers from a text file.
    How to copy the text in rows between numbers from a text file.

    How to copy the text in rows between numbers from a text file.

    3. How to copy the text in rows between numbers from a text file.

    5. How to copy
    the text in rows
    between numbers
    from a text file


    To: Text in text.txt file Example:

    56438(*& 1. How to copy the text in rows
    between numbers from a text file.

    How to copy the text in rows between numbers from a text file.
    How to copy the text in rows between numbers from a text file.

    How to copy the text in rows between numbers from a text file.

    56438(*& 3. How to copy the text in rows between numbers from a text file.

    56438(*& 5. How to copy
    the text in rows
    between numbers
    from a text file
    Last edited by jai0000; 10-10-2022 at 06:27 AM.

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

    Re: How to copy text in excel cell in rows between numbers from a text file.

    OK, I see, but if the code is not working, it is useless anyway.

  20. #20
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: How to copy text in excel cell in rows between numbers from a text file.

    I think, If I can add 56438(*& before these numbers in the text.txt file, using another VBA I can achieve the same result without any issue.

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

    Re: How to copy text in excel cell in rows between numbers from a text file.

    Then you should ask it to the author of that code.

  22. #22
    Registered User
    Join Date
    08-29-2022
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    18

    Re: How to copy text in excel cell in rows between numbers from a text file.

    About question number 1: I think my file may have some formatting issues. I have tried the VBA in different ways. Say there is some issue in the text of number 1111 and then if I delete some text there then the VBA again works up till the next issue say at 2222. If I again delete (randomly a few lines) some text under 2222 then the VBA again works. Really don't know yet what is that. I will post the mock data tomorrow.
    Last edited by jai0000; 10-10-2022 at 11:52 AM.

+ 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. Replies: 3
    Last Post: 08-06-2014, 07:57 AM
  2. Replies: 4
    Last Post: 05-20-2013, 11:37 AM
  3. [SOLVED] HELP with code for copy of some rows from Text file to Excel cells
    By atoppad in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-29-2012, 08:38 PM
  4. Copy cell value, add additonal text and write to Text file
    By emwhite in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2011, 09:47 PM
  5. Copy Excel to Text file and pass Text file to Access Table
    By robbie_xcell in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2011, 01:53 PM
  6. Finding a line in a text file, offset x rows, and copy everything else in the file
    By new.vbacoder in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-27-2010, 12:53 PM
  7. looping, Open text file, copy text, close text file
    By jwilds1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2009, 05:12 PM

Tags for this Thread

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