我的数据如下表所示:
我的数据如上表所示。这个表有很多MMID M000071,M000073,....等。筛选期可能因资产而异。每个MMID可能有几个日期。
我想要输出如下:
表中有20,000个。所以我想找到一个简单的方法来完成这项工作。
答案 0 :(得分:1)
@Jeeped给我一个使用VBA的建议。
因此,通过几个小时的Excel VBA学习,我已经解决了这个问题,并获得了我想要的答案。
代码如下:
Option Explicit
Public Sub sort()
Dim j As Long
Dim cursor As Long
j = 2
cursor = 2
For j = 2 To 20150
X: If Worksheets("Sheet2").Cells(cursor, "A").Value = "" Then
Worksheets("Sheet2").Cells(cursor, "A").Value = Worksheets("Sheet1").Cells(j, "A").Value
Worksheets("Sheet2").Cells(cursor, "H").Value = Worksheets("Sheet1").Cells(j, "D").Value
Select Case Worksheets("Sheet1").Cells(j, "B")
Case "ACR"
Worksheets("Sheet2").Cells(cursor, "B") = Worksheets("Sheet1").Cells(j, "C")
Case "Microalbumin"
Worksheets("Sheet2").Cells(cursor, "C") = Worksheets("Sheet1").Cells(j, "C")
Case "eGFR"
Worksheets("Sheet2").Cells(cursor, "D") = Worksheets("Sheet1").Cells(j, "C")
Case "LDL_HDL_TotChol"
Worksheets("Sheet2").Cells(cursor, "E") = Worksheets("Sheet1").Cells(j, "C")
Case "HbA1C"
Worksheets("Sheet2").Cells(cursor, "F") = Worksheets("Sheet1").Cells(j, "C")
Case "UricAcid"
Worksheets("Sheet2").Cells(cursor, "G") = Worksheets("Sheet1").Cells(j, "C")
End Select
Else
If Worksheets("Sheet1").Cells(j, "A").Value = Worksheets("Sheet2").Cells(cursor, "A").Value Then
If Worksheets("Sheet1").Cells(j, "D").Value = Worksheets("Sheet2").Cells(cursor, "H").Value Then
Select Case Worksheets("Sheet1").Cells(j, "B")
Case "ACR"
Worksheets("Sheet2").Cells(cursor, "B") = Worksheets("Sheet1").Cells(j, "C")
Case "Microalbumin"
Worksheets("Sheet2").Cells(cursor, "C") = Worksheets("Sheet1").Cells(j, "C")
Case "eGFR"
Worksheets("Sheet2").Cells(cursor, "D") = Worksheets("Sheet1").Cells(j, "C")
Case "LDL_HDL_TotChol"
Worksheets("Sheet2").Cells(cursor, "E") = Worksheets("Sheet1").Cells(j, "C")
Case "HbA1C"
Worksheets("Sheet2").Cells(cursor, "F") = Worksheets("Sheet1").Cells(j, "C")
Case "UricAcid"
Worksheets("Sheet2").Cells(cursor, "G") = Worksheets("Sheet1").Cells(j, "C")
End Select
Else
cursor = cursor + 1
GoTo X
End If
Else
cursor = cursor + 1
GoTo X
End If
End If
Next
End Sub
我希望这可以帮助像我这样的其他人。
注意:在运行此程序之前,应将sheet2的单元格MESDATE设置为Text。否则,它会将sheet1的单元格MSEDATE更改为Date类型。
答案 1 :(得分:0)