我想知道是否有一种简单的方法可以将每个Hl7消息的所有行组合到一个单元格中,我有大量的HL7消息列表,并且每个消息都以尖括号“>”结尾。可以使用公式或VBA代码来完成此操作吗?
这是我想要达到的目标
这是一个替代解决方案。它不是很优雅,但是格式与您在上图中所显示的完全一样,每行的末尾都有一个回车符,删除了“>”,并且在消息之间有一个空单元格。我将结果放在B列中,以便可以查看它是否正常运行。您当然可以根据需要进行定制。
Sub DoMessages()
Dim HL7Message As String
Dim newHL7Message As String
Dim i As Integer: i = 2
Dim j As Integer: j = 1
Dim lastRow As Integer
lastRow = Sheets(1).Cells(1000, "A").End(xlUp).Row 'I used "1000" for the sake of this test code. Change as required.
HL7Message = Cells(1, 1).Value
For i = 1 To lastRow
newHL7Message = Cells(i, 1).Value
If Not newHL7Message = ">" Then
If HL7Message = "" Then 'This 'If-Then-Else' keeps from there being an extra CR at the beginning of each cell
HL7Message = newHL7Message
Else
HL7Message = HL7Message & vbCrLf & newHL7Message
End If
Else
Sheets(1).Cells(j, 2) = HL7Message
HL7Message = ""
j = j + 2
End If
Next
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句