文字列の中から特定文字を知りたい時や、入力間違いを発見したい時などに、文字列の中から
特定位置の文字を抽出する必要がある。
セルA3にある文字列 "ABCDEF" の中から、特定位置の文字を抽出する場合
1. Left の構文
Text = Left(Range("A3"),1) ' 引数は左端から何文字を抽出するか
Text2 = Left(Range("A3"),2)
Text3 = Left(Range("A3"),3)
2. Mid の構文
Text4 = Mid(Range("A3"),2,3) ' 引数は何文字目から何文字を抽出するか
Text5 = Mid(Range("A3"),2,4)
Text6 = Mid(Range("A3"),2,5)
3. Rightの構文
Text7 = Right(Range("A3"),1) ' 引数は右端から何文字を抽出するか
Text8 = Right(Range("A3"),2)
Text9 = Right(Range("A3"),3)
基本的なマクロの習得
Left Mid Rightの使用
実際に使っているシステムの内容で解説
EXCEL VBA 講座