Results 1 to 4 of 4

Thread: VBA: Copy files in excel, edit and save

  1. #1
    Banned
    Join Date
    Jul 2017
    Posts
    5
    Rep Power
    0

    VBA: Copy files in excel, edit and save

    Copy .txt files in worksheet with FILENAME (Column B) and FILE DATA (Column C) in the respective cell from a given location(Column A) from folder "Sales_2019"

    Delete lines with given word Sky, Bird, Tree if found in cells

    Then do reverse i.e save the file with FILENAME (Column B) and FILE DATA (Column C) in the respective cell in given location(Column A)

  2. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    Rep Power
    10
    Hello vbadumb.

    I do not understand you.

    _1)
    …. Copy .txt files in worksheet with FILENAME (Column B) and FILE DATA (Column C) …. What does this mean?
    Last edited by DocAElstein; 12-26-2019 at 11:49 PM.

  3. #3
    Banned
    Join Date
    Jul 2017
    Posts
    5
    Rep Power
    0
    _1)
    …. Copy .txt files in worksheet with FILENAME (Column B) and FILE DATA (Column C) …. What does this mean? – Do you want to copy contents of a text file to a column in an Excel worksheet??

    Ans: Yes

    _2)
    …. respective cell from a given location(Column A) from folder "Sales_2019" … This is very confusing to me. I cannot understand what does it mean?

    Ans: same row.

  4. #4
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,313
    Rep Power
    10
    Hello vbadumb.


    _1) To copy contents of a text file to a column in an Excel worksheet
    There are many ways to do that. I am not familiar with them all. Some ways may be better different text files.
    I can show one way that I am familiar with.
    In Brief how it works:
    It gets an entire text file as a single long text string. ( '2a)(i) )
    This string is placed in the windows clipboard ( Rem 3 )
    That string is pasted into a worksheet. ( Rem 4 )




    See attached text file, " vbadumb.txt"

    Inside that text file is 3 lines of data. There is one piece of data in each line, 1 in first line, 2 in second line, and 3 in the third and last line :

    1
    2
    3

    vbatext.JPG : https://imgur.com/WKNmChc
    vbatext.jpg


    Coding description
    The macro here, http://www.excelfox.com/forum/showth...ll=1#post11810 ,gets the entire text file as a single long text string. '2a)(i)
    If we were to examine that string, strtxtFile , then we would see something like
    "1" & vbCr & vbLf & "2" & vbCr & vbLf & "3"

    Rem 3 We can put the string, strtxtFile , into the clipboard. It is somewhat a mystery to most people how all the Microsoft clipboards ( Office Clipboard, Excel Clipboard, Windows Clipboard ) work, but with some practice , we can usually find a way to put a string into the ( Windows ) clipboard, such that the Worksheets .Paste Method used within Excel will recognise that text as a text data range. In our simple example it is relatively easy, since the vbCr & vbLf is recognised by Excel as the row separator. Hence our data would be .Pasted across 3 lines.

    Rem 4 Paste out to the worksheet
    If we have done no other interactions with clipboards from Excel, then it appears that a default link will look for data in the Windows Clipboard.
    If we paste the entire string in / at B1 , then the vbCr & vbLf in the string will be interpreted by Excel as the row separator, so the entire string will be split over 3 lines.
    _____ Workbook: vbadumb.xls ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    1
    1
    2
    2
    3
    3
    4
    Worksheet: FILENAME



    The macro here http://www.excelfox.com/forum/showth...ll=1#post11810 , is also in the attached Excel file, " vbadumb.xls "









    To run a demo , Do this
    Save both files, " vbadumb.txt" and " vbadumb.xls" , in the same Folder
    Run macro,
    Sub txtfilesinworksheetwithFILENAMEColumnB()

    You should then see this in Column B of vbadumb.xls
    vbadumb xls AFTER.JPG : https://imgur.com/6T951BP
    vbadumb xls AFTER.JPG






    _2) I still do not understand what else you want.

    Your explanations are too brief for me to understand. I need full and detailed explanation of all what you want. I am unable to help further without a more detailed explanation of what you want.
    I am away for a few days. If you are able to give a more full explanation, possibly with examples then I will look in again in a few days , if you still then require help

    Otherwise, good luck

    Alan.
    Attached Files Attached Files
    Last edited by DocAElstein; 12-27-2019 at 05:31 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

Similar Threads

  1. Replies: 15
    Last Post: 01-20-2019, 10:16 PM
  2. Replies: 4
    Last Post: 05-08-2014, 10:12 PM
  3. Replies: 9
    Last Post: 05-31-2013, 11:31 PM
  4. Date References to save files using VBA Code
    By mrmmickle1 in forum Excel Help
    Replies: 3
    Last Post: 11-28-2012, 05:48 PM
  5. Macro to copy data from a set of excel files
    By Sreejesh Menon in forum Excel Help
    Replies: 5
    Last Post: 11-15-2012, 11:17 AM

Tags for this Thread

Posting Permissions

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