2017-10-21 96 views
0

我一直在爲這個問題而苦苦掙扎。我在XLS文件中擁有以下大量數據,基本上ColA是隨機的,每個字段中大約有300多個字符。我需要將ColA轉換爲文本文件,ColB和ColC作爲文本文件名。將Excel數據從單個字段導出到TXT

ColA      ColB   ColC 
BLA,432$#@.<>H|3525  John   Smith 
BLA,rewq$#@.<>H|3525  John   Smeeth 
BLA4rew,rerr>H|3525  John   Smamth 

輸出John_Smith.txt從可樂在文件John_Smith.txt中的數據,等等的每一行。

+0

你的意思是在一個文件中可樂第1行,第2行中的其他文件等? – QHarr

回答

0

試試這個,

Sub test() 
    Dim filename As String 
    Dim filecontents As String 
    Dim writerng As Range 
    Dim cell As Range 
    Set writerng = Sheets("Sheet1").Range("A1:A10") 

    For Each cell In writerng 
     filename = cell.Offset(, 1).Value & "_" & cell.Offset(, 2) & ".txt" 
     Open filename For Output As #1 
     filecontents = cell.Value 
     Print #1, filecontents 
     Close #1 
    Next cell 
End Sub