|
▼じゅんじゅん さん:
>▼りんご さん:
>>>じゅんじゅんさん
>>すいません、せっかく教えていただいたんですが、ここでエラーが・・・・
>> Range("P" & i).Value = Left(st, Len(st) - Len(st1))
>>内容もちょっと理解できなくて。VBA初心者ですいません((+_+))
すいませんけども、こちらに差し替えお願いします。
Sub Test2()
Dim Rexp As Object
Dim st As String, st1 As String
Dim Match As Object, Matches As Object
Dim i As Long
Set Rexp = CreateObject("VBScript.Regexp")
Rexp.Pattern = "-[0-9,0-9]+[^-]|号"
For i = 1 To Range("L" & Rows.Count).End(xlUp).Row
st = Range("L" & i).Value
Set Matches = Rexp.Execute(st)
For Each Match In Matches
If Match.Value = "号" Then
st1 = Right(st, Len(st) - (Match.Length + Match.FirstIndex))
ElseIf Match.Length > 0 Then
st1 = Right(st, Len(st) - (Match.Length + Match.FirstIndex - 1))
End If
Exit For
Next Match
Range("P" & i).Value = Left(st, Len(st) - Len(st1))
Range("Q" & i).Value = st1: st1 = ""
Next
End Sub
|
|