[英]Converting all row-column values to column only format
我有一张excel表 。 请查看“示例更正”表。
我有多个带有值的行和列。 我需要仅列格式的所有值。 也就是说, 我需要在单个新列中从2465、2503等到331806的所有值 。 (请忽略工作表中“ K”后的所有值)。
由于间断有空行,中间区域也有不需要的文本,因此我无法应用任何公式或VBA脚本。
参考: https : //www.extendoffice.com/documents/excel/1172-excel-transpose-multiple-columns-into-one-column.html
我尝试了VBA脚本,但仅在所有行都连续显示时才起作用。
这是我的代码:
Sub TableToColumn()
Dim Rng As Range, LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
Set Rng = Range("A" & i, "J" & i) 'Change range to suit needs
Range("M" & Rows.Count).End(xlUp)(2).Resize(Rng.Count) = Application.WorksheetFunction.Transpose(Rng)
Next i
End Sub
此VBA代码提取从A列到J列的所有条目,直到数据存在于行中为止。 如何将其应用于具有更多空行和不需要的原始文本值行的条目表中?
还是通过CSV迁移然后进行正则表达式解析是可行的?
我需要最简单的解决方案。
好吧,让我们尝试一下...
Public Sub Answer()
Dim RowCnt as Integer
Dim Output as Variant
Dim Data as Variant
Data = ThisWorkbook.Worksheets("EXAMPLE CORRECTION").Range("B7:K1384")
' How many rows will we have ?
RowCnt=0
for Row = LBound(Data, 1) to UBound(Data, 1)
for Col = LBound(Data, 2) to UBound(Data, 2)
if Not IsEmpty(Data(Row, Col)) and IsNumeric(Data(Row, Col)) Then RowCnt=RowCnt+1;
Next Col
Next Row
' Resize Output
Redim Output(1 to RowCnt, 1) as Variant
' Fill Output
RowCnt=1
for Row = LBound(Data, 1) to UBound(Data, 1)
for Col = LBound(Data, 2) to UBound(Data, 2)
if Not IsEmpty(Data(Row, Col)) and IsNumeric(Data(Row, Col)) Then
Output(RowCnt, 1) = Data(Row, Col)
RowCnt=RowCnt+1
end if
next
next
' Write to Some Column (Column L) for now
ThisWorkbook.Worksheets("EXAMPLE CORRECTION").Range("L7:L" & RowCnt+6) = Output
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.