I am new to VBA so not have good idea. I have written a code but I am not able to perform specific tasks as I want to perform. If somebody helps me out then I shall be grateful to you. Tasks:
I want to develop just one macro that automatically
1- Import Data from specific cells from Excel sheet to .txt file.
2- Import that data from created .txt file into new excel file. (Note Not want to get data in same excel file I want a new excel file to get open with data in it).
The code I have written for importing data from specific cells in excel files is producing text file where I am not being able to get separate columns (as shown in figure 2 separate columns). This code gives me data but just in 1 column but I want to get data in 2 separate columns.
2nd part of my code works to copy data from text file to excel sheet but in same excel sheet data is being copied means in same excel workbook but in different sheet in that workbook but I want that data should be copied in some other / new excel file/workbook that automatically being generated.
Important every time I update data in excel sheet so data in generated .txt file and new excel file should also be keep on updating.Please have a look at the image/ picture attached.
My Code
Private Sub CommandButton1_Click()
Dim rng As Range
Dim Sourceworksheet As Worksheet
Dim DestFile As String
Dim cel As Range
Application.DefaultFilePath = "C:\Libraries\Documents\"
DestFile = Application.DefaultFilePath & "\Test.txt"
Open DestFile For Output As #1
Set Sourceworksheet = ActiveWorkbook.ActiveSheet
Set rng = Range("A6:B40")
For Each cel In rng.Cells
Write #1, cel.Address & "|" & cel.Value2
Next cel
Close #1
MsgBox "txt file exported"
Dim X As Double
Dim TXT As String
Open "C:\Users\Documents\Test.txt" For Input As #1
X = 0
Do While Not EOF(1)
Line Input #1, TXT
Cells(1, 1).Offset(X, 0) = TXT
X = X + 1
Loop
Close #1
End Sub