Home > Software engineering >  How to EXCEL in the multiple lines to extract information according to the line as much as a TXT fil
How to EXCEL in the multiple lines to extract information according to the line as much as a TXT fil

Time:09-18

As shown below in the EXCEL spreadsheet, how will begin from line 2 line information in column A cell as the file save as TXT file,
For example, to line 2 save for the file name is "111" to TXT, TXT open is shown as: after 111 d DDD
Code 1 characteristic 2
111 d dd
222 e ee
333 f ff
444 g gg
555 h hh
666 I to ii


CodePudding user response:

Write a simple Excel VBA code, reference,
Open the Excel (open document), and then open the VBE varies, insert a standard module, add the following code:
 Option Explicit 

Public Sub Main ()
Dim strPath As String
Dim strTemp As String
Dim As Long I

StrTemp=InputBox (" enter the path to save the TXT file: ", "file path")
If (" "=strTemp) Then
Call MsgBox (" output path is not specified, termination of operations, ", 64 & amp; , the "message")
The Exit Sub
End the If
StrPath=strTemp & amp; ""
I=2 & amp; 'data from line 2
Do
'suppose the data in the current workbook Sheet1
StrTemp=Trim $(Sheet1. Cells (I, 1). The Value)
If (" "=strTemp) Then Exit the Do 'empty cell end
The Open strPath & amp; StrTemp & amp; ". TXT "For the Output As the # 1
Print # 1, strTemp; VbTab;
Print # 1, Sheet1. Cells (I, 2). The Value; VbTab;
Print # 1, Sheet1. Cells (I, 3)
Close # 1
I=1 & amp; + I
Loop
If (2 & amp;=I) Then
Call MsgBox (" no data output, ", 64 & amp; , the "message")
The Else
Call MsgBox (" output operation is completed, ", 64 & amp; , the "message")
End the If
End Sub

CodePudding user response:

The above line of code, 22 accidentally less input. Value, should be:
Print # 1, Sheet1. Cells (I, 3). The Value

, however, can be omitted. The Value, try once, default attributes should be with the Value attribute values are the same,
  •  Tags:  
  • VBA
  • Related