[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『市、区、町、村で分ける』(いいち)
A2=LEFT(A1,FIND("市",A1))で市だけは分割出来たのですが同時に 区、町、村の場合も分割出来るよう数式を入れたいのですが応用 が分かりません。OR関数かな?とは思い試してみましたがなかなか うまくゆきません。よろしくお願いします。
全文検索すれば、いろいろと出てくるはず。 [[20070605151955]]『郵便番号を振り分ける』(zamasu) (ぽ)
おはようございま〜す。。。♪
限定した少ないデータでしたら 関数でも可能かも知れませんけれど 住所の分割は、かなり難しいです。。
ぽさんのリンクされた検索箇所とか
[[20050121161337]] 『住所の分割』(りんご)
[[20040831081709]] 『住所セルの分割』(ピヨ)
の中の弥太郎さんの スペシャル関数は、いかがでしょうか?
どんな住所を分割されたいのかも 書かれた方が良いと思います。。。
ご参考にどうぞ。。。
。。。Ms.Rin〜♪♪
折角Ms.Rin〜♪♪はんが紹介してくれてますんで、ニューバージョンを披露しときま すワ。(笑 今度のんは行がずれとってもOKですし、エラーもでまへん。 町、村で分割するのは、例えば「京都市左京区烏丸通り長者町下る」こういった町と して成立しない住所がしこたまありますんでそれには対処しとりまへん。 区も又然りです。 使い方は 複数を一挙に分割するばやいは=adrs1(a1:a500)などと入力します。 単独で 都道府県、市区、その他 は=adrs1(a1) =adrs2(a1) =adrs3(a1)などと それぞれのセルに入力して、以下にコピーする方法にも対応しとります。 (弥太郎) 標準モジュールへ '------------------------- Public x As Variant Dim sp1 As String, sp2 As String, sp3 As String
Function adrs2(adrs As Range) work (adrs) adrs2 = sp2 End Function Function adrs3(adrs As Range) work (adrs) adrs3 = sp3 End Function
Function adrs1(adrs As Range) Application.EnableEvents = True If adrs.Rows.Count > 1 Then ReDim x(1 To adrs.Rows.Count, 1 To 3) For i = 1 To adrs.Rows.Count x(i, 1) = "=adrs1(" & adrs(i, 1).Address(0, 0) & ")" x(i, 2) = "=adrs2(" & adrs(i, 1).Address(0, 0) & ")" x(i, 3) = "=adrs3(" & adrs(i, 1).Address(0, 0) & ")" Next i adrs1 = Empty Exit Function End If work (adrs) adrs1 = sp1 End Function Sub work(adrs) Dim fist_Cnt As Integer, lngh As Integer Dim data As String, get_data As String data = adrs
With CreateObject("vbscript.regexp") .Pattern = "^(東京都|大阪府|京都府|北海道)|^(..|...)県" If .test(adrs) Then sp1 = .Execute(adrs)(0) data = Mid(adrs, .Execute(adrs)(0).Length + 1) Else sp1 = "" End If .Pattern = "市" If .test(data) Then fist_Cnt = .Execute(data)(0).firstindex .Pattern = "^(八日市場|市川|市原|今市|四日市|八日市|廿日市)市" If .test(data) Then sp2 = .Execute(data)(0) lngh = .Execute(data)(0).Length Else .Pattern = "^(余市|高市)郡" If .test(data) Then sp2 = .Execute(data)(0) lngh = .Execute(data)(0).Length Else .Pattern = "^(郡上|小郡|郡山|蒲郡|大和郡山)市" If .test(data) Then sp2 = .Execute(data)(0) lngh = .Execute(data)(0).Length Else .Pattern = "^.+郡" If .test(data) Then sp2 = .Execute(data)(0) lngh = .Execute(data)(0).Length Else sp2 = Left(data, fist_Cnt + 1) lngh = Len(sp2) End If End If End If data = Mid(data, lngh + 1) .Pattern = "^.+区" If Right(sp2, 1) = "市" And .test(data) Then get_data = .Execute(data)(0) If .Execute(data)(0).Length < 6 Then .Pattern = "([\d0-9]|一|二|三|四|五|六|七|八|九|十|公園|須岡|城西|八迫|由宇町.|太田中|太田北|金生字.)区" If Not .test(data) Then .Pattern = "(見市笠原町|部市生地|諸市東区)" If Not .test(adrs) Then sp2 = sp2 & get_data data = Mid(data, Len(get_data) + 1) End If End If End If End If End If
ElseIf sp1 = "東京都" Or sp1 = "" Then .Pattern = "^.+区" If .test(data) Then sp2 = .Execute(data)(0) data = Mid(data, .Execute(data)(0).Length + 1) End If Else .Pattern = "^.+郡" If .test(data) Then sp2 = .Execute(data)(0) data = Mid(data, .Execute(data)(0).Length + 1) End If End If End With sp3 = data End Sub
'そのシートモジュールへ ’----------------------- Private Sub Worksheet_Change(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Left(Target.Formula, 7) <> "=adrs1(" Then Exit Sub If Not Target.Formula Like "*:*" Then Exit Sub Application.EnableEvents = False Target.Resize(UBound(x), 3) = x Application.EnableEvents = True
End Sub
「市区」までは分解できますが、その先「町、字」で一区切り(地方なもので(笑))「番地(数字)」で最終くくりの感じでバージョンUPなんて考えてますでしょう? 一人ごとでした。
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.