|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub test()
Dim i&, j&, k&
Dim arr, brr() As String, mypath As String
Application.ScreenUpdating = False
With Sheet1
arr = .Range("a1:C" & .Range("a65536").End(xlUp).Row) '第1行数据无用,排除后方便些;若这样,见下面的注释
End With
j = UBound(arr) - 1 '排除多余1行
ReDim brr(1 To j * 2) '
For i = 2 To UBound(arr) '用UBound(arr) 或 j+1 ,把减的加上。
k = k + 1 'k变量用来计数
brr(k) = arr(i, 1) & "—A—" & arr(i, 2)
brr(k + j) = arr(i, 3) & "—B—" & arr(i, 2)
Next i
mypath = ThisWorkbook.Path & "\测试.txt"
Open mypath For Output As #1
Print #1, Join(brr, vbCrLf)
Close #1
Application.ScreenUpdating = True
End Sub |
|