|
では、これでどうかな・・?
Sub Check_Data2()
Dim Ary As Variant, Ary2 As Variant
Dim i As Long, Num As Single
Dim C As Range
Dim V As String, MyS As String, RetSt As String
Const CkSt As String = _
"N20,(Z2.4),N20,(Z-6.0),N30,(Z1.0),N20,(Z-3.5),N30,(Z-5.0)"
Application.ScreenUpdating = False
Range("IT1:IU1").Value = Array("Data1", "Data2")
Ary = Split(CkSt, ")")
For i = 0 To UBound(Ary) - 1
V = CStr(Ary(i)): Ary2 = Split(V, "Z")
MyS = Ary2(0)
Num = Val(Ary2(1))
If Left$(MyS, 1) = "," Then
MyS = Right$(MyS, Len(MyS) - 1)
End If
Cells(i + 2, 254).Value = MyS
Cells(i + 2, 255).Value = Num
Erase Ary2
Next i
Range("IT:IU").Sort Key1:=Range("IT1"), Order1:=xlAscending, _
Key2:=Range("IU1"), Order2:=xlAscending, Header:=xlYes, _
Orientation:=xlSortColumns
With Range("IU2", Range("IU65536").End(xlUp)).Offset(, 1)
.Formula = "=IF($IT1<>$IT2,$IU2)"
For Each C In .SpecialCells(3, 1)
RetSt = RetSt & C.Offset(, -2).Value & _
"Z" & Format(C.Value, "###.0") & "),"
Next
'.CurrentRegion.ClearContents
End With
RetSt = Left$(RetSt, Len(RetSt) - 1)
Application.ScreenUpdating = True
Debug.Print RetSt
End Sub
加工前の文字例としては、上(CkSt)のようになるべくいろいろなケースを
交えた方がいいです。なぜなら例文では偶然できたけど、他の文字列で
やってみたら希望の形と違っていた、という可能性が高くなるからです。
|
|