数据量大的话建议用VBA
1、由于以下VBA将所选择的区域转换到A列中,如果A列包含数据,先在工作表的最左侧插入一新的A列,以便放置转换后的数据。
2、按快捷键Alt+F11,打开VBA编辑器,在右侧代码窗口中粘贴下列代码:
Sub 选定区域转换为一列并去除空格()
Dim TheRng, TempArr
Dim i As Integer, j As Integer, elemCount As Integer
On Error GoTo line1
Range("a:a").ClearContents
If Selection.Cells.Count = 1 Then
Range("a1") = Selection
Else
TheRng = Selection
elemCount = UBound(TheRng, 1) * UBound(TheRng, 2)
ReDim TempArr(1 To elemCount, 1 To 1)
For i = 1 To UBound(TheRng, 1)
For j = 1 To UBound(TheRng, 2)
TempArr((i - 1) * UBound(TheRng, 2) + j, 1) = TheRng(i, j)
Next
Next
Range("a1:a" & elemCount) = TempArr
End If
line1:
Dim r As Long
r = Sheet1.UsedRange.Rows.Count
For i = r To 1 Step -1
If Cells(i, 1) = "" Then
Rows(i).Delete
End If
Next
End Sub
3、关闭VBA编辑器,返回Excel工作表界面。
4、全选需要转换的区域(千万记得要做这个步骤!!!),再按Alt+F8,打开“宏”对话框,选择上述代码中的宏名“选定区域转换为一列并去除空格”,运行代码。
H1公式:
=INDIRECT(TEXT(SMALL(IF($A$1:$E$10="",6553601,(ROW($1:$10)*100+COLUMN($A:$E))),ROW(A1)),"R0C00"),)&""
按CTRL+SHIFT+ENTER键结束,下拉填充.
=INDIRECT(ADDRESS(INT(ROW(A5)/5),MOD(ROW(A5),5)+1))
下拉填充
是需要转置吗?最好把图贴上来看看