代码如下。。。
Sub CombineColumns1()
'updateby Extendoffice
Dim xRng As Range
Dim i As Integer
Dim xLastRow As Integer
Dim xTxt As String
' On Error Resume Next
xTxt = Application.ActiveWindow.RangeSelection.Address
Set xRng = Application.InputBox("请选择区域", "多列转两列", xTxt, , , , , 8)
If xRng Is Nothing Then Exit Sub
ReDim arr(1 To 10000, 1)
brr = xRng
xLastRow = xRng.Columns(1).Rows.Count + 1
For j = 1 To xRng.Columns.Count
For i = 2 To xRng.Rows.Count
If brr(i, j) <> Empty Then
n = n + 1
arr(n, 0) = brr(1, j)
arr(n, 1) = brr(i, j)
End If
Next
Next
Set xRng = Application.InputBox("请选择区域", "输出位置", xTxt, , , , , 8) '点击一个单元格,输出位置
xRng.Resize(n, 2) = arr
End Sub
|