我需要根据编号格式将数据从 1 个 excel 移动到另一个 excel。例如,我按照以下示例 test1 excel:
测试1.xlsx
EName| Sal | ID | Tel | Add | Depart | Pos |
------------------------------------------------------------
John | 10000 | 123| NA | NY | Finance | Manager |
------------------------------------------------------------
1 | 5 | 2 | | | 3 | 4 |
列按数字排列。在这种情况下,我需要将我的数据移动到另一个 excel 中 test2 并以编号格式粘贴。
测试.xlsx
Name | ID | Department | Level |Position | Salary |
1 | 2 | 3 | | 4 | 5 |
John | 123| Fiinanace | NA |Manager | 10000 |
由数字标识的每一列的值。我如何做到这一点。非常感谢任何建议/参考。谢谢
Sub startGenerateExcel()
Path1 = Range("F4").Value
Path2 = Range("F6").Value
Dim wbSource As Workbook
Dim wbDest As Workbook
Dim rngSource As Range
Dim rngDest As Range
Dim colNum As Integer
Dim colDest As Integer
Dim cl As Range
Set wbSource = Workbooks(Path1)
Set wbDest = Workbooks(Path2)
Set rngSource = wbSource.Sheets("Sheet1").Range("A1:G3") 'Modify as needed
Set rngDest = wbDest.Sheets("Sheet1").Range("A1:F3") 'Modify as needed
For Each cl In rngSource.Rows(2)
colNum = cl.Offset(1, 0).Value
colDest = Application.Match(colNum, rngDest.Rows(3), False)
rngDest.Cells(2, colDest).Value = cl.Value
Next
End Sub