[[20070129190214]] 『顧客名簿の作成』(のだ) ページの最後に飛ぶ

[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]

 

『顧客名簿の作成』(のだ)

今まで手書きしていた顧客名簿をパソコンで管理したく、

名簿にある郵便番号・住所(○県○市○区○○1-2-3)・名前

と数十件入力して、最終的にはこれを区ごとに分けたいのですが

どういう手順で何をすれば出来ますか?

データの並び替えでやってみたのですが、うまくいきません…

県は全て同じで市と区が違います。

うまく伝わったか分かりませんが…どなたかアドバイスお願いします。


 >住所(○県○市○区○○1-2-3)
これは1つのセルに入力ですか?
なら
見出しの住所を選択し
データ>フィルタ>オートフィルタ
で出てきた▼をポチッとすると
オプションというのがあるので、
○○区を含むで抽出する
あるいは、郵便番号で抽出する方法もありますね
                         (oni)

 郵便番号の一覧が↓で入手できます
http://www.post.japanpost.jp/zipcode/dl/kogaki.html

 県ごとにありCSVなのでそのままExcelに取り込めます
 コチラを利用してVLOOKUPで市や区を抽出してはいかがでしょうか?

 (e1tw)VLOOKUP
https://www.excel.studio-kazu.jp/func/vlookup.html

 (Ohagi)

 先ず初めにAlt+F11でVBEを開き 挿入→標準モジュールを選択して下のコードを
 コピペします。
 仮にデータがA2から郵便番号 B2が住所 C2が名前とデータが並んどるとします。
 E2に=adrs2(B2)で下方向にコピーで市区が抽出でけますから、今度はF2に=kuwake(E2)
 とすると区だけが抽出でけます。
 これも下方向へコピーし、今度はA列からF列までのデータ範囲を選択し、データ→
 並べ換えで優先順位F列にしてOKを押すと、区単位に見事並べかえられます。
 E列F列をクリア、Alt+F11でModule1を右クリック→Module1を解放すれば残るのはキレ
 いに並べ変えられたデータが残るだけとなります。
     (弥太郎)
 '-----------------------
 Dim fstdata As String, scnddata As String, srddata As String
Dim data As String
Public x As Variant
Public adrs As Range
Function adrs2(adrs As Range)
    data = adrs.Value
    sp = 2
    work (sp)
    adrs2 = scnddata
 End Function
Sub work(sp)
    Dim Rex As Object
    Dim sp_data As String
    Set Rex = CreateObject("vbscript.regexp")

    sp_data = ""
    Rex.Pattern = "^(大阪府|京都府|東京都|北海道)"
    If Rex.test(data) Then
        sp_data = Rex.Execute(data)(0)
    Else
        Rex.Pattern = "(^..|神奈川|和歌山|鹿児島)県"
        If Rex.test(data) Then
            sp_data = Rex.Execute(data)(0)
        End If
    End If
    fstdata = sp_data
    mid_cnt = Len(fstdata)
    get_data = Mid(data, mid_cnt + 1)
    n = InStr(get_data, "市")
    city = InStr(n + 1, get_data, "市")
    gun = InStr(get_data, "郡")
    If n <> 0 Then
        If city <> 0 And city < 6 Then
            Rex.Pattern = "^(八日市場|市川|市原|今市|四日市|八日市|廿日市)市"
            If Rex.test(get_data) Then
                sp_data = Rex.Execute(get_data)(0)
                mid_cnt = mid_cnt + Rex.Execute(get_data)(0).Length
            Else
                Rex.Pattern = "^余市郡"
                If Not Rex.test(get_data) Then
                    Rex.Pattern = "市"
                    If Rex.test(get_data) Then
                        sp_data = Left(get_data, Rex.Execute(get_data)(0) _
                                    .firstindex + 1)
                        mid_cnt = mid_cnt + n
                    End If
                End If
            End If

        ElseIf gun <> 0 And n > gun Then
            Rex.Pattern = "^(郡上|小郡|郡山|蒲郡|大和郡山)市"

            If Rex.test(get_data) Then
                sp_data = Rex.Execute(get_data)(0)
                mid_cnt = mid_cnt + Len(sp_data)
            End If

        ElseIf gun <> 0 And n < gun Then
            Rex.Pattern = "^高市郡"
            If Not Rex.test(get_data) Then
                    Rex.Pattern = "市"
                    If Rex.test(get_data) Then
                        sp_data = Left(get_data, Rex.Execute(get_data)(0).firstindex + 1)
                        mid_cnt = mid_cnt + n
                    End If
             End If
        Else
            If n <> 1 Then
                sp_data = Mid(get_data, 1, n)
                mid_cnt = mid_cnt + n
            End If

        End If
    End If

    get_data = Mid(data, mid_cnt + 1)
    n = InStr(get_data, "区")

    If n > 1 And n < 6 Then
        Rex.Pattern = "([0-90-9]|一|二|三|四|五|六|七|八|九|十|公園|須岡|城西|八迫|由宇町.|太田中|太田北|金生字.)区"
        If Not Rex.test(get_data) Then
            Rex.Pattern = "(見市笠原町|部市生地|諸市東区)"
            If Not Rex.test(data) Then
                If Right(sp_data, 1) = "市" Then
                    sp_data = Left(sp_data, Len(sp_data))
                End If
                sp_data = sp_data & Mid(get_data, 1, n)
                mid_cnt = mid_cnt + n
            End If
        End If
    End If
    get_data = Mid(data, mid_cnt + 1, 69)
    Rex.Pattern = "(市|区)"

    If Not Rex.test(sp_data) Then
        Rex.Pattern = "^(.+郡)"
        If Rex.test(get_data) Then
            sp_data = Rex.Execute(get_data)(0)
            mid_cnt = mid_cnt + Rex.Execute(get_data)(0).Length
            scnddata = sp_data
        End If
    End If
    scnddata = sp_data
    srddata = Mid(data, mid_cnt + 1)
 End Sub

 Function kuwake(adrs As Range)
    With CreateObject("vbscript.regexp")
        .Pattern = "(\W+)*市(.+区)"
        If .test(adrs) Then
            kuwake = .Replace(adrs, "$2")
        Else
            kuwake = ""
        End If
    End With
 End Function


コメント返信:

[ 一覧(最新更新順) ]


YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki. Modified by kazu.