スナックelve 本店

バツイチ40代女の日記です

年賀状中間状況(調整中)

f:id:elve:20211205171356p:plain
年賀状続き
データはダミー。
郵便番号のハイフンいらない
数字全角
(ハイフンは全角にすると回転しちゃうので半角で(;´Д`))
f:id:elve:20211205170023p:plain
後、 名字2文字名前2文字のバランスが悪いからスペース入れてみる。
名前一文字のバランスの悪さがなぁ・・・。
 
修正後
f:id:elve:20211205170216p:plain
Excel

  • 氏名
  • 姓<必須>
  • 名<必須>
  • 連名
  • 連名2
  • 連名3
  • 連名4
  • 氏名(ひらがな)
  • 年齢
  • 生年月日
  • 郵便番号<必須>
  • 住所<必須>
  • 住所1
  • 住所2
のリストを作りまして、シート2に
「都道府県コード及び市区町村コード」のR1.5.1現在の団体シートから都道府県と市区町村をあわせたリスト
を貼り付けておきます。(これが住所1に入り、以降が住所2に)

Sheet1

Option Explicit

Sub changeDATA()
Dim e As Integer: e = Range("A1").End(xlDown).Row
Dim i As Integer
Dim l As Integer
Dim na
Columns("K:K").NumberFormatLocal = "@"

For i = 2 To e
'名前が長かったら姓にスペース(1文字姓はそのまま)
    If Len(Cells(i, 2)) > 1 Then
        Cells(i, 15).FormulaArray = "=MAX(LEN(RC[-12]:RC[-8]))"
        If Len(Cells(i, 2)) < Cells(i, 15) + 1 Then
            Cells(i, 2) = " " & Cells(i, 2)
        End If
    End If
'郵便番号
    Cells(i, 11) = CStr(Replace(Cells(i, 11), "-", ""))
'住所
    Cells(i, 12) = StrConv(Cells(i, 12), vbWide)
    Cells(i, 12) = Replace(Cells(i, 12), "-", "-")
    l = Sheet2.Searchaddress(Cells(i, 12))
    'If l = 0 Then MsgBox ("エラー")
    Cells(i, 13) = Left(Cells(i, 12), l)
    Cells(i, 14) = Right(Cells(i, 12), Len(Cells(i, 12)) - l)

'住所の長さ
    Cells(i, 15).Formula2R1C1 = "=Len(RC[-3])"
Next
    Me.UsedRange.Sort Cells(1, 15), xlDescending, , , , , , xlYes
End Sub

sheet2の方に関数を。うぅ、固定値使っちゃう。

Option Explicit

Function Searchaddress(allstr As String) As Integer
    Searchaddress = 0
    Dim adr: adr = WorksheetFunction.Transpose(Range("A2:A1748"))
    Dim e As Integer: e = 1748 - 1
    Dim i As Integer
    For i = 1 To e
        If allstr Like (adr(i) & "*") Then
            Searchaddress = Len(adr(i))
            Exit For
        End If
    Next
    
End Function

ん~なんかかっこ悪いんだよなぁ~