公報データの分析では公報発行年のデータを使用することが多い。
公報データには発行年月日が有るが、年月日データのままではうまく処理できなかったので、以下のように、年データだけの文字列に変換して利用している。
'変数を宣言
Dim SHEETNAME01 As String
Dim NY1 As Long, NX1 As Integer
Dim y As Long,nclm1 As Integer
'シート名称設定
SHEETNAME01 = "重複なしデータ"
'
'処理対象のカラム数を指定
nclm1 = 3 '発行日欄
'==============
' 発行年を追加する
'==============
Sheets(SHEETNAME01).Select
Cells(1, 1).Select
ActiveCell.CurrentRegion.Select
NY1 = Selection.Rows.Count
NX1 = Selection.Columns.Count
' 発行年の欄を右横に追加
Cells(1, NX1 + 1) = "発行年"
'年データを抽出
For y = 2 To NY1
Cells(y, NX1 + 1) = Year(Cells(y, nclm1))
Next y
'文字列表記に変更
Columns(NX1 + 1).Select
Selection.NumberFormatLocal = "G/標準"
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
これにより、発行年を文字データとして元の表の右横に追加できる。