excel-formula - 如何根据 Id 列将行转置为列
解决方案
我认为用 excel 公式创建类似的东西是不可能的。我尝试创建一个可能有助于使用 VBA 的代码。
尝试:
Option Explicit
Sub test()
Dim LR As Long, LC As Long, i As Long, No As Long
With ThisWorkbook.Worksheets("Sheet1")
LR = .Cells(.Rows.Count, "A").End(xlUp).Row
.Cells(LR + 3, 1).Value = "Event_Id"
.Cells(LR + 4, 1).Value = "1"
.Cells(LR + 5, 1).Value = "2"
.Cells(LR + 6, 1).Value = "3"
For i = 2 To LR
No = .Cells(i, 1).Value
If No = "1" Then
LC = .Cells(LR + 4, .Columns.Count).End(xlToLeft).Column
If .Cells(LR + 3, LC + 1).Value = "" Then
.Cells(LR + 3, LC + 1).Value = "Unit_Id"
End If
.Cells(LR + 4, LC + 1).Value = .Cells(i, 2).Value
If .Cells(LR + 3, LC + 2).Value = "" Then
.Cells(LR + 3, LC + 2).Value = "Qty"
End If
.Cells(LR + 4, LC + 2).Value = .Cells(i, 3).Value
ElseIf No = "2" Then
LC = .Cells(LR + 5, .Columns.Count).End(xlToLeft).Column
If .Cells(LR + 3, LC + 1).Value = "" Then
.Cells(LR + 3, LC + 1).Value = "Unit_Id"
End If
.Cells(LR + 5, LC + 1).Value = .Cells(i, 2).Value
If .Cells(LR + 3, LC + 2).Value = "" Then
.Cells(LR + 3, LC + 2).Value = "Qty"
End If
.Cells(LR + 5, LC + 2).Value = .Cells(i, 3).Value
ElseIf No = "3" Then
LC = .Cells(LR + 6, .Columns.Count).End(xlToLeft).Column
If .Cells(LR + 3, LC + 1).Value = "" Then
.Cells(LR + 3, LC + 1).Value = "Unit_Id"
End If
.Cells(LR + 6, LC + 1).Value = .Cells(i, 2).Value
If .Cells(LR + 3, LC + 2).Value = "" Then
.Cells(LR + 3, LC + 2).Value = "Qty"
End If
.Cells(LR + 6, LC + 2).Value = .Cells(i, 3).Value
End If
Next i
End With
End Sub
推荐阅读
- cron - Cron 作业 - Azure Azcopy ini 文件
- api - API 中的不同后端终结点取决于 Azure API 管理中的产品
- c# - 如何修复“无法对空引用执行运行时绑定”
- c# - 从 C# 执行 Oracle 存储过程 - 调用中的参数数量或类型错误
- php - PHP + SQL - 使用 SQL Server 'Create To' 脚本通过 PHP 创建表
- ios - 客户端按时间戳过滤订单文本消息
- vba - 带有查找代码的 VBA 错误 13
- angular - Ngxs - 承诺行动链?
- android - 打开键盘会提升我的整体视图 React-Native
- javascript - 阴影不适用于 THREE.js