此宏仅在我从A22-78中选择并控制C行时有效。 我希望它能在没有我必须这样做的情况下工作。 此函数从(#rows)*(每行中的#列)
中生成一列Sub RowsToColumn()
Dim RN As Range
Dim RI As Range
Dim r As Long
Dim LR As Long
Dim WS As Worksheet
Set WS = Sheets.Add
Application.ScreenUpdating = False
Columns(1).Insert
r = 0
LR = Range("B" & Rows.Count).End(xlUp).Row
For Each RN In Range("B22:B" & LR)
r = r + 1
For Each RI In Range(RN, Range("XFD" & RN.Row).End(xlToLeft))
r = r + 1
Cells(r, 1) = RI
RI.Clear
Next RI
Next RN
Columns("A:A").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
Application.ScreenUpdating = True
End Sub
谢谢你
答案 0 :(得分:1)
我尝试了你的代码,它似乎做的是从左到右读取值,并按相应的顺序将它们全部放在A列中。 这有用吗:
Sub Test()
Dim oRange As Range
Dim oSheet As Excel.Worksheet
Dim vArray() As Variant
Dim lCnt_A As Long
Dim iCnt_B As Integer
Dim lCnt_C As Long
Dim iCnt_Cols As Integer
Set oSheet = ThisWorkbook.Sheets(1)
Columns(1).Insert
Set oRange = oSheet.UsedRange
iCnt_Cols = oRange.Columns.Count
vArray = oRange
oRange.ClearContents
For lCnt_A = 1 To UBound(vArray)
For iCnt_B = 1 To iCnt_Cols
lCnt_C = lCnt_C + 1
ThisWorkbook.Sheets(2).Cells(lCnt_C, 1).Value = vArray(lCnt_A, iCnt_B)
Next iCnt_B
Next lCnt_A
Set oSheet = Nothing
Set oRange = Nothing
End Sub
如果我的意图错了,请告诉我。