When there are multiple rows of data in Excel, we also need to store each row of data into a TXT document, do we need to manually Ctrl + c --> Ctrl + V --> Ctrl + S? The answer is no doubt. Wow, I need to process a document that stores more than 60 thousand pieces of data. In order to cherish my life, I will use VBA in the office to speculate!
Use the shortcut key Alt + F11 to open the Excel VBA and enter the following code:
Private Sub CommandButton1_Click() Application.ScreenUpdating = False Dim nRow As Long nRow = Range("a65536").End(xlUp).Row For i = 1 To nRow Open ThisWorkbook.Path & "\文件" & i & ".txt" For Output As #1 Print #1, Range("a" & i) Close #1 Next Application.ScreenUpdating = True MsgBox "ok"End Sub
Click Run.
However, when the main user sees that when I disable VBA, the special functions of this document cannot be seen, and a button control is added to excel. In the development tool, click the control, click the button, double-click the button, and enter the above Code.
How to store each row in Excel as a TXT document