|
关于你的这个问题,我做了个视频教程,发布在B站:
https://www.bilibili.com/video/BV1434y167kY?share_source=copy_web
使用到的代码如下,希望能够帮助到你!
Sub byWanao()
Dim Dic As Object, arr, i%, j%
Set Dic = CreateObject("Scripting.Dictionary")
arr = Sheet1.UsedRange
For j = 1 To UBound(arr, 2)
Dic(arr(1, j)) = j
Next
For i = 2 To UBound(arr)
For j = 1 To UBound(arr, 2)
Sheet2.Cells(i, j) = arr(i, Dic(Sheet2.Cells(1, j).Value))
Next
Next
Stop
End Sub
Sub byWanao2()
Dim Dic As Object, i%, j%
Set Dic = CreateObject("Scripting.Dictionary")
For j = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
Dic(Cells(1, j).Value) = j
Next
For i = 2 To Cells(1, 1).End(xlDown).Row
For j = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
Cells(i + 12, j) = Cells(i, Dic(Cells(13, j).Value))
Next
Next
End Sub |
|