SQL:
抽出
SELECT * FROM TB; SELECT [商品コード], [商品名] FROM TB; SELECT * FROM TB WHERE [商品名] = 'リンゴ'; SELECT * FROM TB WHERE [商品名] LIKE = '%リンゴ%'; -- 「リンゴ」を含む WHERE [商品名] LIKE = 'リンゴ%'; -- 「リンゴ」で始まる WHERE [商品名] LIKE = '%リンゴ'; -- 「リンゴ」で終わる WHERE [商品名] LIKE = '_リンゴ%'; -- 2文字目から「リンゴ」で始まる WHERE [商品名] LIKE = 'リンゴ_'; -- 「リンゴ」の後ろに1文字:計4文字
UPDATE
/* 単価すべてを x 1.1 */ UPDATE T商品マスタ SET 単価 = 単価 * 1.1; /* 単価を x 1.1 */ UPDATE T商品マスタ SET 単価 = 単価 * 1.1; WHERE 商品名 LIKE 'リンゴ%';
INSERT
/* */ INSERT INTO T商品マスタ VALUE ('A004', 'リンゴジュース', 120); /* */ INSERT INTO T商品マスタ('商品コード', '商品名', '価格') VALUE ('A004', 'リンゴジュース', 120);
DELETE
/* テーブルすべて */ DELETE FROM T商品マスタ VALUE ('A004', 'リンゴジュース', 120); /* */ DELETE FROM T商品マスタ WHERE [商品コード] = 'A004' ;
ORDER BY
/* ASC(ascending order):昇順 (scend:上昇 )*/ /* DESC(descending order):降順 (de- : 下降)*/ SELECT 商品名 FROM商品マスタ ORDER BY 単価 ASC, 商品ID DESC;
集計
- SUM
- AVG
- MAX
- MIN
- COUNT
SELECT AVG(単価) FROM T商品マスタ WHERE [商品名] = '%リンゴ%' ;
いろいろ
SELECT 商品名 FROM TB_商品マスタ SELECT [商品ID],[商品名] FROM TB_商品マスタ SELECT 商品名 FROM TB_商品マスタ WHERE 単価 <= 100; SELECT 商品名 FROM TB_商品マスタ WHERE 単価 != 100; SELECT 商品名 FROM TB_商品マスタ WHERE 単価 <> 100; SELECT 商品名 FROM TB_商品マスタ WHERE 分類 ='周辺機器'; /* ケーブルを含む */ SELECT 商品名 FROM TB_商品マスタ WHERE 商品名 LIKE '%ケーブル%'; /* 2文字目からケーブル */ SELECT 商品名 FROM TB_商品マスタ WHERE 商品名 LIKE '_ケーブル%'; /* _を含む */ SELECT 商品名 FROM TB_商品マスタ WHERE 商品名 LIKE '%\_%' ESCAPE '\'; /* 日付 */ SELECT 商品名 FROM TB_商品マスタ WHERE 処理日 >= '2010-04-01' AND 処理日 <= '2011-03-31'; /* BETWEEN */ SELECT 商品名 FROM TB_商品マスタ WHERE 処理日 BETWEEN '2010-0401' AND '2011-03-31; /* AND・OR */ SELECT 商品名 FROM TB_商品マスタ WHERE (分類 ='周辺機器') OR (分類 = 'ネットワーク機器'); SELECT 商品名 FROM TB_商品マスタ WHERE NOT (分類 ='周辺機器') AND (分類 = 'ネットワーク機器'); /* IN/NOT IN*/ SELECT 商品名 FROM TB_商品マスタ WHERE 分類 IN('周辺機器' , 'ネットワーク機器'); SELECT 商品名 FROM TB_商品マスタ WHERE 分類 NOT IN('周辺機器' , 'ネットワーク機器'); /* IS NULL / IS NOT NULL*/ SELECT 商品名 FROM TB_商品マスタ WHERE 単価 IS NUL; SELECT 商品名 FROM TB_商品マスタ WHERE 単価 IS NULL;
/* テーブル結合 */ SELECT TB_A.処理日, TB_B.商品ID FROM 売上げデータ TB_A, 商品マスタ TB_B WHERE TB_A.商品ID = TB_B.商品ID; /* 並び替え(ASC:昇順)(DESC:降順) */ SELECT 商品名 FROM商品マスタ ORDER BY 単価 ASC, 商品ID DESC; /* COUNT */ SELECT COUNT(単価) AS カウント FROM 商品マスタ -- NULLは、カウントされない /* GROUP BY */ SEKECT 分類, COUNT(*) FROM 商品マスタ GROUP BY 分類 ORDER BY 分類 /* SUM */ SELECT B.商品名 , SUM(A.数量) FROM 売上げデータ A, 商品マスタ B WHERE A.商品ID = B.商品ID GROUP BY B.商品名 ORDER BY B.商品名
/* HAVING*/ SELECT B.商品名, SUM(A.数量) FROM 売上げデータ A, 商品マスタ B GROUP BY B.商品名 HAVING SUM(A.数量) >= 5 ORDER BY B.商品名 -- 売上げが5個以上の商品名と売上げ個数
VBA:Excel :辞書
参考
【Excel VBA入門】Dictionaryとは?データ管理が楽になる連想配列の作り方 – Valmore
【エクセルVBA】Dictionaryに格納したキーと要素をリストに書き出す方法
【VBA入門】Dictionaryオブジェクト(連想配列)の使い方 | 侍エンジニアブログ
Dictionary オブジェクト | Microsoft Docs
MSリファレンス
Dim d 'Create a variable Set d = CreateObject("Scripting.Dictionary") d.Add "a", "Athens" 'Add some keys and items d.Add "b", "Belgrade" d.Add "c", "Cairo" ...
メソッド | 説明 |
---|---|
Add | Dictionary オブジェクトに新しいキー/アイテムのペアを追加します。 |
Exists | 指定したキーが Dictionary オブジェクト内に存在するかどうかを示すブール値を返します。 |
Items | Dictionary オブジェクト内のすべてのアイテムの配列を返します。 |
Keys | Dictionary オブジェクト内のすべてのキーの配列を返します。 |
Remove | Dictionary オブジェクトから、指定したキー/アイテムのいずれかのペアを削除します。 |
RemoveAll | Dictionary オブジェクト内のすべてのキー/アイテムのペアを削除します。 |
プロパティ | 説明 |
---|---|
CompareMode | Dictionary オブジェクト内でキーを比較するために比較モードを設定するか返します。 |
Count | Dictionary オブジェクト内のキー/アイテムのペアの数を返します。 |
Item | Dictionary オブジェクト内のアイテムの値を設定するか返します。 |
Key | Dictionary オブジェクト内の既存のキー値に対して新しいキー値を設定します。 |
サンプル
Public Sub aTEST_Dictionary() '=========================================================== '【事前バインディング】 ' Microsoft Scripting Runtime ' Dim dicUser As Dictionary ' Set dicUser = New Dictionary '=========================================================== '【遅延バインディング】 ' Dim Dictionary名 As Object ' Set Dictionary名 = CreateObject("Scripting.Dictionary") '=========================================================== '===================================================== '// 追加・削除・取得・カウント・KEY存在確認 '===================================================== Dim dic01 As Dictionary Set dic01 = New Dictionary '// 追加 dic01.Add "KEY", "VAL" 'HDR dic01.Add "a", "AAAA" 'Add some keys and items dic01.Add "b", "BBBB" dic01.Add "c", "CCCC" '// カウント Debug.Print dic01.Count '// カウント '// 取得 Debug.Print dic01.Item("b") '// KeyのValue Debug.Print dic01.Keys(0) '// HDR Value Debug.Print dic01.Items(0) Debug.Print dic01.Item(dic01.Keys(0)) '// HDR Value Dim vFE_Key As Variant For Each vFE_Key In dic01 Debug.Print vFE_Key, dic01(vFE_Key) Next vFE_Key '// IsExists If Not dic01.Exists("d") Then dic01.Add "d", "DDDD" If Not dic01.Exists("d") Then dic01.Add "d", "DDDD" Debug.Print "キー名一覧: " & Join(dic01.Keys, " | ") Debug.Print "値一覧 : " & Join(dic01.Items, " | ") '// dic01.Remove "b" Debug.Print "キー名一覧: " & Join(dic01.Keys, " | ") Debug.Print "値一覧 : " & Join(dic01.Items, " | ") '// dic01.RemoveAll Debug.Print "キー名一覧: " & Join(dic01.Keys, " | ") Debug.Print "値一覧 : " & Join(dic01.Items, " | ") End Sub
VBA:Excel :コレクション
参考
コレクションとは(Collection)|VBA入門
Collection オブジェクト | Microsoft Docs
Add メソッド (Visual Basic for Applications) | Microsoft Docs
Item メソッド (Visual Basic for Applications) | Microsoft Docs
Remove メソッド (Visual Basic for Applications) | Microsoft Docs
Count プロパティ (Visual Basic for Applications) | Microsoft Docs
【Excel VBA入門】Collectionとは?サイズ変更に強いリストの作り方 – Valmore
[VBA]Collectionを知り、使い方を知る
コレクションのコレクション
行列データでデータラベル(説明)を付けてみる
Collection(Collection(Collection(Collection)))【LOOPデータ】
全体:行:列:データ詳細
Dim all_Collecction As Collection Set all_Collecction = New Collection Dim lRow As Long For lRow = 1 To 7 '// 7行 Dim r_Collecction As Collection Set r_Collecction = New Collection Dim lCol As Long For lCol = 1 To 5 '// 5列 Dim c_Collecction As Collection Set c_Collecction = New Collection '============================================ ' データ詳細(名前付きデータ) '============================================ Dim lDat As Long For lDat = 1 To 5 '// 6データ '------------------------------------------- Dim dat_Collecction As Collection '------------------------------------------- Set dat_Collecction = New Collection '// 初期化 Call dat_Collecction.Add("LABEL_" & lDat) '// データ作成 Call dat_Collecction.Add(lDat) '// データ作成 Call c_Collecction.Add(dat_Collecction) '// 1つ上に格納 '------------------------------------------- Set dat_Collecction = Nothing '// 1つ上に格納したら、次のために解放 '------------------------------------------- Next lDat '// カラムの塊を1行のエリアへ Call r_Collecction.Add(c_Collecction) '// 1つ上に格納 Set c_Collecction = Nothing '// 1つ上に格納したら、次のために解放 Next lCol '// 行の塊を全データのエリアへ Call all_Collecction.Add(r_Collecction) '// 1つ上に格納 Set r_Collecction = Nothing '// 1つ上に格納したら、次のために解放 Next lRow Debug.Print "行数 : " & all_Collecction.Count Debug.Print "列数 : " & all_Collecction.Item(1).Count Debug.Print "データ数 : " & all_Collecction.Item(1)(1).Count '// 1行,2列,5番目データのラベル Debug.Print "データ_ラベル : " & all_Collecction.Item(1)(2)(3)(1) '// 1行,2列,5番目データのデータ Debug.Print "データ_Data : " & all_Collecction.Item(1)(2)(3)(2) End Sub
Collection(Collection(Collection(Collection))) 【個別データ】
全体:行:列:データ詳細
Public Sub mth_Collection() Dim all_Collecction As Collection Set all_Collecction = New Collection Dim lRow As Long For lRow = 1 To 7 '// 7行 Dim r_Collecction As Collection Set r_Collecction = New Collection Dim lCol As Long For lCol = 1 To 5 '// 5列 Dim c_Collecction As Collection Set c_Collecction = New Collection '============================================ ' データ詳細(名前付きデータ) '============================================ '------------------------------------------- Dim dat_Collecction As Collection '------------------------------------------- Set dat_Collecction = New Collection Call dat_Collecction.Add("行番号") Call dat_Collecction.Add(lRow) Call c_Collecction.Add(dat_Collecction) '// データの塊を1カラムのエリアへ Set dat_Collecction = New Collection Call dat_Collecction.Add("列番号") Call dat_Collecction.Add(lCol) Call c_Collecction.Add(dat_Collecction) '// データの塊を1カラムのエリアへ Set dat_Collecction = New Collection Call dat_Collecction.Add("色データ_" & lCol) Call dat_Collecction.Add("255,0," & lCol) Call c_Collecction.Add(dat_Collecction) '// データの塊を1カラムのエリアへ Set dat_Collecction = New Collection Call dat_Collecction.Add("数式") Call dat_Collecction.Add("=SUM()") Call c_Collecction.Add(dat_Collecction) '// データの塊を1カラムのエリアへ '------------------------------------------- Set dat_Collecction = Nothing '------------------------------------------- '// カラムの塊を1行のエリアへ Call r_Collecction.Add(c_Collecction) Set c_Collecction = Nothing Next lCol '// 行の塊を全データのエリアへ Call all_Collecction.Add(r_Collecction) Set r_Collecction = Nothing Next lRow Debug.Print "行数 : " & all_Collecction.Count Debug.Print "列数 : " & all_Collecction.Item(1).Count Debug.Print "データ数 : " & all_Collecction.Item(1)(1).Count '// 1行,2列,3番目データのラベル Debug.Print "データ_ラベル : " & all_Collecction.Item(1)(2)(3)(1) '// 1行,2列,3番目データのデータ Debug.Print "データ_Data : " & all_Collecction.Item(1)(2)(3)(2) End Sub
Collection(Collection(Collection(Array)))
全体:行:列:データ詳細(配列)
Public Sub mth_Collection_Arr() Dim all_Collecction As Collection Set all_Collecction = New Collection Dim lRow As Long For lRow = 1 To 7 '// 7行 Dim r_Collecction As Collection Set r_Collecction = New Collection Dim lCol As Long For lCol = 1 To 5 '// 5列 Dim c_Collecction As Collection Set c_Collecction = New Collection '============================================ ' データ詳細(名前付きデータ) '============================================ '------------------------------------------- Dim dat_Collecction As Collection '------------------------------------------- Dim Arr() Arr = Array("行番号", lRow) Call c_Collecction.Add(Arr) '// データの塊を1カラムのエリアへ Arr = Array("列番号", lCol) Call c_Collecction.Add(Arr) '// データの塊を1カラムのエリアへ Arr = Array("色データ_" & lCol, "255,0," & lCol) Call c_Collecction.Add(Arr) '// データの塊を1カラムのエリアへ Arr = Array("数式", "=SUM()") Call c_Collecction.Add(Arr) '// データの塊を1カラムのエリアへ '------------------------------------------- Set dat_Collecction = Nothing '------------------------------------------- '// カラムの塊を1行のエリアへ Call r_Collecction.Add(c_Collecction) Set c_Collecction = Nothing Next lCol '// 行の塊を全データのエリアへ Call all_Collecction.Add(r_Collecction) Set r_Collecction = Nothing Next lRow Debug.Print "行数 : " & all_Collecction.Count Debug.Print "列数 : " & all_Collecction.Item(1).Count Debug.Print "データ数 : " & all_Collecction.Item(1)(1).Count '// 1行,2列,3番目データのラベル Debug.Print "データ_ラベル : " & all_Collecction.Item(1)(2)(3)(0) '// 1行,2列,3番目データのデータ Debug.Print "データ_Data : " & all_Collecction.Item(1)(2)(3)(1) End Sub
Collection(Collection(Collection(Array_2D)))
全体:行:列(配列:1次元):データ詳細(配列:2次元)
※列用Collectionは、Array_2Dを格納する1つだけ
Public Sub mth_Collection_Arr2D() Dim all_Collecction As Collection Set all_Collecction = New Collection Dim lRow As Long For lRow = 1 To 7 '// 7行 Dim r_Collecction As Collection Set r_Collecction = New Collection Dim lCol As Long For lCol = 1 To 5 '// 5列 Dim c_Collecction As Collection Set c_Collecction = New Collection '============================================ ' データ詳細(名前付きデータ) '============================================ Dim Arr(3, 1) Arr(0, 0) = "行番号" Arr(0, 1) = lRow Arr(1, 0) = "列番号" Arr(1, 1) = lCol Arr(2, 0) = "色データ_" & lCol Arr(2, 1) = "255,0," & lCol Arr(3, 0) = "数式" & lCol Arr(3, 1) = "=SUM()" Call c_Collecction.Add(Arr) '// データの塊を1カラムのエリアへ '// カラムの塊を1行のエリアへ Call r_Collecction.Add(c_Collecction) Set c_Collecction = Nothing Next lCol '// 行の塊を全データのエリアへ Call all_Collecction.Add(r_Collecction) Set r_Collecction = Nothing Next lRow Debug.Print "行数 : " & all_Collecction.Count Debug.Print "列数 : " & all_Collecction.Item(1).Count Debug.Print "データ数 : " & all_Collecction.Item(1)(1).Count '// 1行,2列,3番目データのラベル '// 最後の要素は1個で2次元配列 Debug.Print "データ_ラベル : " & all_Collecction.Item(1)(2)(1)(2, 0) '// 1行,2列,3番目データのデータ Debug.Print "データ_Data : " & all_Collecction.Item(1)(2)(1)(2, 1) End Sub
[検索]文字のアドレスをコレクションで取得
'************************************************************************* '機能 : [検索]文字のアドレスをコレクションで取得 '戻り値 : 'ARG1 : 'ARG2 : '説明 : '************************************************************************* Private Sub btn_Collect_01_Click() Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets("debug") Dim colRes_Collect As Collection Set colRes_Collect = m_検索.mth_GetCellAddress_Sheet(ws, "検索") Debug.Print colRes_Collect.Count Dim vFE As Variant For Each vFE In colRes_Collect Debug.Print vFE Next vFE Set ws = Nothing End Sub '************************************************************************* '機能 : シート全体、指定文字列のアドレス検索 '戻り値 : アドレスコレクション 'ARG1 : WorkSheet 'ARG2 : 検索文字列 '説明 : '************************************************************************* Public Function mth_GetCellAddress_Sheet( _ ws As Worksheet, _ sSrhString _ ) As Collection Dim sRes_Address() As String Dim sRes_Address_Collects As Collection Set sRes_Address_Collects = New Collection Dim v As Variant Dim rngFindCell As Range Dim rngFind_1st As Range Dim rngFind_List As Range '=========================== '// 検索 '=========================== 'LookIn:=xlValues 値検索 'LookAt:=xlWhole 完全一致 'MatchCase:=true 大文字と小文字を区別する(True) 'MatchByte:=True 半角と全角を区別する(True) 'SearchFormat 書式を検索しない(False) Set rngFindCell = ws.Cells.Find( _ what:=sSrhString, _ LookIn:=xlValues, _ LookAt:=xlWhole, _ MatchCase:=True, _ MatchByte:=True, _ SearchFormat:=False _ ) If rngFindCell Is Nothing Then Exit Function Else Set rngFind_1st = rngFindCell Set rngFind_List = rngFindCell End If '-------------------------------------------- '// 検索 → Rangeリスト追加 '-------------------------------------------- Do '// 以降の検索条件も同一で検索 Set rngFindCell = ws.Cells.FindNext(rngFindCell) '// 検索不一致時はループを抜ける If rngFindCell Is Nothing Then Exit Do End If '// 処理 If rngFindCell.Address = rngFind_1st.Address Then Exit Do '// 最初に見つかったものと同じなら終了 Else 'Find_Listに追加していく Set rngFind_List = Union(rngFind_List, rngFindCell) End If Loop '--------------- '// Result '--------------- For Each v In rngFind_List Call sRes_Address_Collects.Add(v.Address) Next Set mth_GetCellAddress_Sheet = sRes_Address_Collects '--------------- '// 後処理 '--------------- Set rngFindCell = Nothing Set rngFind_1st = Nothing Set rngFind_List = Nothing Set sRes_Address_Collects = Nothing End Function
コレクション 削除
'// Dim i As Long For i = 1 To all_Collecction.Count all_Collecction.Remove 1 Next i
ジャグ構造 ⇒ 矩形構造
'** '* ジャグ構造 ⇒ 矩形構造 '* '* parg {} '* @arg_ref {} '* @arg_opt {} '* @ret {} '* '* @note '* Public Sub mth_Collection_ジャグ() Dim i As Long Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets("コレクション") Dim lRow_Start As Long: lRow_Start = 3 Dim lRow_End As Long: lRow_End = 16 '// 参考:行まとめデータ Dim Row_Collecction As Collection Set Row_Collecction = New Collection '// Dim All_Collecction As Collection Set All_Collecction = New Collection '####################################################### Dim lRow As Long For lRow = lRow_Start To lRow_End '// 行範囲 '####################################################### '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ' 指定列:行データ取得 ' 行 → 列 変換データ '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Dim Cell_Dat As Collection Set Cell_Dat = New Collection '============================================ ' データ詳細(名前付きデータ) '============================================ Dim lCol_Data As Long For lCol_Data = 6 To 11 '------------------------------------------- Dim chip_Dat As Collection '------------------------------------------- Dim rng As Range Set rng = ws.Cells(lRow, lCol_Data) ' If rng.Value <> "" Then Set chip_Dat = New Collection '// 初期化 Call chip_Dat.Add(rng.Address) '// データラベル Call chip_Dat.Add(rng.Value) '// データ Call Cell_Dat.Add(chip_Dat) '// 格納 ' End If '------------------------------------------- Set chip_Dat = Nothing '// 格納したら、次のために解放 '------------------------------------------- Next lCol_Data '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ' 行セルデータを列セルデータへ変換(行列変換):1行分 '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& For i = 1 To Cell_Dat.Count Dim ColToRow As Collection Set ColToRow = New Collection '//## 行番号 ################### Set chip_Dat = New Collection '// 初期化 Call chip_Dat.Add("RowNo") '// データラベル Call chip_Dat.Add(lRow) '// データ '// データペアを格納 Call ColToRow.Add(chip_Dat) '//## Cells(Row,2) ################### Set chip_Dat = New Collection '// 初期化 Call chip_Dat.Add("Cells(" & lRow & ",2)") '// データラベル '// データ(空白の場合、1つ上のデータペアと同じにする) If lRow = lRow_Start _ Or Trim(ws.Cells(lRow, 2).Value) <> "" _ Then Call chip_Dat.Add(ws.Cells(lRow, 2).Value) Else Call chip_Dat.Add(All_Collecction.Item(All_Collecction.Count - 1)(ColToRow.Count + 1)(2)) End If '// データペアを格納 Call ColToRow.Add(chip_Dat) '//## Cells(Row,3) ################### Set chip_Dat = New Collection Call chip_Dat.Add("Cells(" & lRow & ",3)") '// データ(空白の場合、1つ上のデータペアと同じにする) If lRow = lRow_Start _ Or Trim(ws.Cells(lRow, 3).Value) <> "" _ Then Call chip_Dat.Add(ws.Cells(lRow, 3).Value) Else Call chip_Dat.Add(All_Collecction.Item(All_Collecction.Count - 1)(ColToRow.Count + 1)(2)) End If Call ColToRow.Add(chip_Dat) '//## Cells(Row,4) ################### Set chip_Dat = New Collection Call chip_Dat.Add("Cells(" & lRow & ",4)") '// データ(空白の場合、1つ上のデータペアと同じにする) If lRow = lRow_Start _ Or Trim(ws.Cells(lRow, 4).Value) <> "" _ Then Call chip_Dat.Add(ws.Cells(lRow, 4).Value) Else Call chip_Dat.Add(All_Collecction.Item(All_Collecction.Count - 1)(ColToRow.Count + 1)(2)) End If Call ColToRow.Add(chip_Dat) '//## Cells(Row,5) ################### Set chip_Dat = New Collection Call chip_Dat.Add("Cells(" & lRow & ",5)") Call chip_Dat.Add(ws.Cells(lRow, 5).Value) Call ColToRow.Add(chip_Dat) '//## 行列変換データを1ペアずつ ##################### Call ColToRow.Add(Cell_Dat.Item(i)) '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ '$$$ 全データ領域 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Call All_Collecction.Add(ColToRow) '// 1レコードずつ Next i '// ※行ごとに分割する場合↓ Call Row_Collecction.Add(ColToRow) '// 1行ずつ '####################################################### Next lRow '####################################################### 'Collect(Row)(Col)(1):データラベル 'Collect(Row)(Col)(2):データ '===================================== '// 全データ確認用 表示 '===================================== Dim r As Long Dim c As Long For r = 1 To All_Collecction.Count For c = 1 To All_Collecction.Item(r).Count ws.Cells(20 + r, c).Value = All_Collecction.Item(r)(c)(2) Next c Next r '===================================== '// 空白削除処理 '===================================== Dim DelNoData_Row As Collection Set DelNoData_Row = New Collection For r = 1 To All_Collecction.Count Dim DelNoData_Col As Collection Set DelNoData_Col = New Collection For c = 1 To All_Collecction.Item(r).Count '// 6列目にデータがあるものを追加 '// ※行列変換したデータ Debug.Print All_Collecction.Item(r)(6)(2) If All_Collecction.Item(r)(6)(2) <> "" Then Dim Buf As Collection Set Buf = New Collection Buf.Add (All_Collecction.Item(r)(c)(1)) '// Collect(Row)(Col)(1):データラベル Buf.Add (All_Collecction.Item(r)(c)(2)) '// Collect(Row)(Col)(2):データ Call DelNoData_Col.Add(Buf) Set Buf = Nothing End If Next c If DelNoData_Col.Count > 0 Then Call DelNoData_Row.Add(DelNoData_Col) Else 'NOP End If Set DelNoData_Col = Nothing Next r '===================================== '// 削除済データ確認用 表示 '===================================== For r = 1 To DelNoData_Row.Count For c = 1 To DelNoData_Row.Item(r).Count ws.Cells(20 + r, c).Offset(0, 8).Value = DelNoData_Row.Item(r)(c)(2) Next c Next r End Sub
VBA:Excel :フォーム/コンボボックス
Listから選択
Private Sub UserForm_Initialize() Me.cbo.Style = fmStyleDropDownList Me.cbo.Clear Me.cbo.AddItem "a" Me.cbo.AddItem "b" Me.cbo.AddItem "c" Me.cbo.AddItem "d" Me.cbo.AddItem "e" End Sub Private Sub CommandButton1_Click() Dim i As Long For i = 0 To Me.cbo.ListCount - 1 If Me.cbo.List(i) = "c" Then Me.cbo.ListIndex = i End If Next i End Sub
VBA:文字列
- 文字コード(Asc / Chr)
- 文字列変換(StrConv)
- 大文字/小文字(UCase / LCase / Format)
- 文字数/バイト数(Len)
- 抜出し(Left / Right / Mid)
- 比較・検索(Instr / StrComp / Like)
- 変更・置換(Replace / StrReverce)
- 前後のスペース(LTrim / RTrim / Trim)
- 連続文字の作成(String)
- 日付(Format)
- 書式設定(Format)
- 配列:分割・結合・検索(Split / Join / Filter)
[参考]
VBA関数
文字コード(Asc / Chr)
[参考]
Asc関数,AscB関数,AscW関数
Chr関数,ChrB関数,ChrW関数
文字列変換(StrConv)
[参考]
StrConv関数