用Excel将Excel单元格放在Excel中

所以,我有一个macros导出到CSV格式的数据,它的工作很好(代码在底部)。 问题是我正在把它的数据。 当我把有问题的数据出来

名字,姓氏,用户名,密码,描述

我想改变它,所以我得到

名字姓氏,名字,姓氏,用户名,密码,说明

我想要做的是操纵现有的macros,所以做到这一点。 我不擅长VBS,所以任何投入或推动正确的方向将是太棒了。

谢谢!

代码来自用户Chance2 http://www.excelforum.com/excel-programming/679620-set-up-macro-to-export-as-csv-file.html 。 公平是正确的,作者应该被正确归因。 我很抱歉做任何这种声音专有。

Sub Make_CSV() Dim sFile As String Dim sPath As String Dim sLine As String Dim r As Integer Dim c As Integer r = 1 'Starting row of data sPath = "C:\CSVout\" sFile = "MyText_" & Format(Now, "YYYYMMDD_HHMMSS") & ".CSV" Close #1 Open sPath & sFile For Output As #1 Do Until IsEmpty(Range("A" & r)) 'You can also Do Until r = 17 (get the first 16 cells) sLine = "" c = 1 Do Until IsEmpty(Cells(1, c)) 'Number of Columns - You could use a FOR / NEXT loop instead sLine = sLine & """" & Replace(Cells(r, c), ";", ":") & """" & "," c = c + 1 Loop Print #1, Left(sLine, Len(sLine) - 1) 'Remove the trailing comma r = r + 1 Loop Close #1 End Sub 

最简单的改变是将“姓氏姓氏”连接分配给sLine ,即:

 Do Until IsEmpty(Range("A" & r)) 'You can also Do Until r = 17 (get the first 16 cells) sLine = """" & Replace(Cells(r,1) & " " & Cells(r,2), ";", ":") + """," c = 1 Do Until IsEmpty(Cells(1, c)) 'Number of Columns - You could use a FOR / NEXT loop instead sLine = sLine & """" & Replace(Cells(r, c), ";", ":") & """" & "," c = c + 1 Loop Print #1, Left(sLine, Len(sLine) - 1) 'Remove the trailing comma r = r + 1 Loop