|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 合并()
Set wb = ThisWorkbook.Sheets(1) '计算行数列数可以扩展(行随意,列到9列)
ha = wb.Range("A65536").End(3).Row
lie = wb.Range("1:1").End(xlToRight).Column
k = 2 '记录结果填充起始行
wb.Range("M2:N" & wb.Range("M65536").End(3).Row).Clear '清除上次数据
For j = 2 To lie
For i = 2 To ha
If Cells(i, j) <> "" Then
Cells(k, 13) = Cells(i, 1)
Cells(k, 14) = Cells(i, j)
k = k + 1
End If
Next i
Next j
'水平垂直自动居中
With wb.Cells
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Sub
|
|