How to copy past data from excel sheet to txt file

Let there is table (please take a look in attachment "for forum" ). I need to write VBA code that makes txt file and  copy past needed data to this txt file. ( please take a look in attachment output txt file "testing " )

Many thx in advance !
For-forum.xlsx
testing.txt
SunnyXAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rob HensonFinance AnalystCommented:
You don't have to use VBA if you don't particularly need to.

On a separate tab use formula to copy the data from the columns required, eg:

A1  =Sheet1!B8

Copied across until you get to the column for the date and time and make that:

=TEXT(Sheet1!G8,"mm/dd/yyyy hh:mm")

Copy down as many rows as required.

With this sheet selected do a File - Save As and choose TXT in the File type list. Only the visible sheet will be saved and it will be text values as required.

Thanks
Rob H
0
Rob HensonFinance AnalystCommented:
Alternatively with the Excel file and Notepad open. Select the required data on the Excel sheet and Copy. Go to Notepad and just paste. Save notepad file, will be txt by default.

Thanks
Rob H
0
Roy CoxGroup Finance ManagerCommented:
Try this


Option Explicit
Sub test()
    Dim TempSht As Worksheet
    Dim rRng As Range
    Dim sFullPath As String
    sFullPath = ThisWorkbook.Path & Application.PathSeparator

    With Sheet1
        Set rRng = .Range(.Cells(8, 2), .Cells(.Rows.Count, 7).End(xlUp))
    End With
    Set TempSht = Sheets.Add
    rRng.Copy TempSht.Range("A1")
    TempSht.Copy
    ActiveWorkbook.SaveAs Filename:=sFullPath & "testing.txt", FileFormat:=xlCSV, CreateBackup:=False
    Application.DisplayAlerts = False
    TempSht.Delete
    ActiveWorkbook.Close True
    Application.DisplayAlerts = True
End Sub

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

SunnyXAuthor Commented:
@Roy_Cox,

Thx you so much. However, in my file separation between data row is tabulation and your code makes separation by comma. Could you tell me what I should change in order to make separation by tabulation ("Tab" key in the keyboard ). This is crucial for me because, before my request, I  start to form my data base by using tabulation as separation.

Many thx in advance.
0
Roy CoxGroup Finance ManagerCommented:
Change the FileFormat to xlText.

Option Explicit


Sub ConvertToTabDelimited()
    Dim TempSht As Worksheet
    Dim rRng As Range
    Dim sFullPath As String
    sFullPath = ThisWorkbook.Path & Application.PathSeparator
    With Application
        .ScreenUpdating = False
        On Error GoTo err_quit
        With Sheet1
            Set rRng = .Range(.Cells(8, 2), .Cells(.Rows.Count, 7).End(xlUp))
        End With
        Set TempSht = Sheets.Add
        rRng.Copy TempSht.Range("A1")
        TempSht.Copy
        ActiveWorkbook.SaveAs Filename:=sFullPath & "testing.txt", FileFormat:=xlText, CreateBackup:=False
        .DisplayAlerts = False
        TempSht.Delete
        ActiveWorkbook.Close True
        .DisplayAlerts = True

err_quit:
        .ScreenUpdating = True
    End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SunnyXAuthor Commented:
Thx u so much !
0
Roy CoxGroup Finance ManagerCommented:
I'm pleased it helped
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.