Sub 年齢を年代に置換変換する()
'A列の最終行を取得する
最終行 = Cells(Rows.Count, "A").End(xlUp).Row
For 行数 = 2 To 最終行 '2行数目~最終行まで変換する
If 10 <= Cells(行数, "A") And Cells(行数, "A") < 20 Then '10~20の場合
Cells(行数, "A") = "10代" '10代上書き
ElseIf 20 <= Cells(行数, "A") And Cells(行数, "A") < 30 Then '20~30の場合
Cells(行数, "A") = "20代" '20代上書き
ElseIf 30 <= Cells(行数, "A") And Cells(行数, "A") < 40 Then '30~40の場合
Cells(行数, "A") = "30代" '30代上書き
'40代50代などその他の追加はElseIfをコピペすればOK
End If
Next 行数
End Sub
この場合、数が限られているので、見にくくはありますが、Replaceを使って
Columns("A").Replace What:="21", Replacement:="20代", LookAt:=xlWhole '21→20代
Columns("A").Replace What:="22", Replacement:="20代", LookAt:=xlWhole '22→20代
Columns("A").Replace What:="23", Replacement:="20代", LookAt:=xlWhole '23→20代
・
・
・
31→30代
32→30代
33→30代
・
・
・
みたいに置換をする方法でも可能です。
ご自身の理解のしやすさに合わせてご使用ください。