Excel 选择唯一行并将其值复制为transpose
我试图选择唯一的行,并将它们的值复制为差异表中的转置 我的意思是使VBA代码动态 这里有一个例子Excel 选择唯一行并将其值复制为transpose,excel,transpose,vba,Excel,Transpose,Vba,我试图选择唯一的行,并将它们的值复制为差异表中的转置 我的意思是使VBA代码动态 这里有一个例子 Raw Excel x 1 x 2 x 3 y 4 y 5 z 6 Desired output x y z 1 4 6 2 5 3 试试这个 Sub a() DataRow = 1 DataCol = 1 OutputRow = 1 OutputCol = 4 Application.ScreenUpdating = False OutputCol = OutputCol - 1
Raw Excel
x 1
x 2
x 3
y 4
y 5
z 6
Desired output
x y z
1 4 6
2 5
3
试试这个
Sub a()
DataRow = 1
DataCol = 1
OutputRow = 1
OutputCol = 4
Application.ScreenUpdating = False
OutputCol = OutputCol - 1
While Cells(DataRow, DataCol).Value <> 0
Cells(DataRow, DataCol).Select
ThisValue = Cells(DataRow, DataCol).Value
If ThisValue <> PrevValue Then
OutputCol = OutputCol + 1
MyRow = OutputRow
Cells(MyRow, OutputCol).Value = Cells(DataRow, DataCol).Value
MyRow = OutputRow + 1
End If
Cells(MyRow, OutputCol).Value = Cells(DataRow, DataCol + 1).Value
PrevValue = ThisValue
DataRow = DataRow + 1
MyRow = MyRow + 1
Wend
Application.ScreenUpdating = True
End Sub
suba()
DataRow=1
数据列=1
OutputRow=1
输出col=4
Application.ScreenUpdating=False
输出列=输出列-1
While单元格(数据行、数据列)。值0
单元格(数据行、数据列)。选择
ThisValue=单元格(数据行、数据列).Value
如果此值大于此值,则
输出列=输出列+1
MyRow=OutputRow
单元格(MyRow,OutputCol).Value=单元格(DataRow,DataCol).Value
MyRow=OutputRow+1
如果结束
单元格(MyRow,OutputCol).Value=单元格(DataRow,DataCol+1).Value
PrevValue=此值
DataRow=DataRow+1
MyRow=MyRow+1
温德
Application.ScreenUpdating=True
端接头