目次 †
内容 †
準備など †
自分の環境で使えるようにする †
モジュールの削除 †
- モジュールを選択し、右クリックの「<<モジュール名>>の開放」を選択
セルの値を操作 †
セルを選ぶ(2種類ある) †
Range("A1").select
Cells( 1, 2 ).select '順番に注意→「縦」「横」
文字列の取得 †
MsgBox( Range("A1").value )
連続したセルを選択 †
Range("A18").Select
Range(Selection, Selection.End(xlDown).End(xlToRight)).Select
文字列操作 †
文字列があるか? †
If InStr("東京都港区", "東京都") = 1 Then
MsgBox "東京です"
End If
文字列の抜き出し(ExcelのMidコマンド) †
idstr = Mid("東京都港区", 1, 3)
英数字のみ半角(参考:OKウェブ) †
Function NarrowChange(ByVal strString As String) As String
Dim intLength As Integer
Dim strCut As String
intLength = Len(strString)
Do While strString <> ""
strCut = Left(strString, 1)
If (strCut >= "0" And strCut <= "9") _
Or (strCut >= "A" And strCut <= "Z") _
Or (strCut >= "a" And strCut <= "z") Then
NarrowChange = NarrowChange & StrConv(strCut, vbNarrow)
Else
NarrowChange = NarrowChange & strCut
End If
strString = Mid(strString, 2)
Loop
End Function
連想配列 †
参考 †
使用例 †
' 宣言
Dim ken_list
Set ken_list = CreateObject("Scripting.Dictionary")
' 値のセット
ken_list.Add "愛知県", "うなぎ"
ken_list.Add "愛媛県", "みかん"
ken_list.Add "茨城県", "納豆"
' 値の取り出し
if ( ken_list. Exists("愛知県") Then
MsgBox ken_list("愛知県")
end if
' 全ての要素に処理
Dim item
For Each item In ken_list.keys
MsgBox item
Next item
ファイル操作 †
参考 †
FileSystemObjectのインスタンス †
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
その他 †
画面描写の更新を行わない †
Application.ScreenUpdating = False