
(excel・一括処理)「読み仮名」の入ったセルを「振り仮名」に反映する
エクセルの一括処理で、読み仮名の入ったセル(B列)をA列の「ふりがな」として設定する方法を記載しておきます。
excelメニューの「開発」→「visual basic」→「挿入」→「標準モジュール」を選択して、以下を貼り付ける。
Sub ApplyPhoneticToAllRows()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim kanjiCell As Range
Dim readingCell As Range
' 現在のシートを取得
Set ws = ThisWorkbook.ActiveSheet
' 最終行を指定
lastRow = 6418
' A列とB列の各行をループ
For i = 3 To lastRow
Set kanjiCell = ws.Cells(i, "A")
Set readingCell = ws.Cells(i, "B")
' 読みが存在する場合
If Not IsEmpty(readingCell.Value) Then
' A列のセルに振り仮名を設定
kanjiCell.Value = kanjiCell.Value ' セルの値をそのまま設定
' 振り仮名を追加
kanjiCell.Characters(1, Len(kanjiCell.Value)).PhoneticCharacters = readingCell.Value
End If
Next i
End Sub
最終行を適宜変更し、保存する。
保存(Ctrl+S)して、実行(F5)する。
以上
いいなと思ったら応援しよう!
