あちこちいくからメモる(´・ω・`)
選択範囲
dim r as range
set r = selection
' ActiveWindow.RangeSelection
範囲の値
1,000.0
range("a1").value ' 1000
range("a1").text ' 1,000.0
ブック(ファイル)・オープン
option explicit
option private module
public function bookopen()
dim file_name as variant
file_name = application.getopenfilename("text file(*.xls;*.xls), *.xls;*.xlsm")
if file_name <> false then
workbooks.add file_name
bookopen = file_name
end If
end function
ぶぁりあんと返ってくるとは思わなかったよ。
テーブルの積み上げ
dim target as range 'テーブルの範囲 e.g. range("a2:e2")
sub ins()
target.row.hidden = true
target.insert xlshiftdown
end sub
sub del()
target.delte xlshiftup
end sub
' ユーティリティ
function empty_record() As boolean
dim idx As Long
with target
for idx = 1 to .columns.count
if .offset(1, 0).cells(1, idx).value <> "" then
empty_record = false
exit function
end if
next
end with
empty_record = true
end function
こんなの
挿入後
行を消すのはカウンターあったほうがいいかな。
フィルター
オートフィルタ
2015/2/1 ~ 2015/2/15 の間を抽出
dim target as range
sub fil()
dim hit as long
target.autofilter 1, ">2015/2/1", xland, "<=2015/2/15", true
' range_expr.autofilter(filed, criteria1, operator, criteria2, visibledropdown) : variant
' field 抽出条件のターゲット
' criteria1 抽出条件1:variant
' operator XlAutoFilterOperator列挙
' criteria2 抽出条件2:variant
' visibledropdown true|false
' 抽出された数
hit = target.autofileter.filters.count
end sub
sub revert
if worksheets(index).autofiltermode then
worksheets(index).autofiltermode = false
end if
end sub
アドバンス・フィルター
対象のデータ、抽出条件、抽出結果を別々のシートでできる!
dim target as range
sub adv_fil
dim src as range
dim dst as range
dim cond as worksheet
dim query as range
set src = worksheets(1).target
set dst = worksheets(3).target
set cond = worksheets(2)
set query = cond.range("...")
src.advancedfiletr xlfiltercopy, query, dst, false
end sub
抽出条件
よくわからない。
Excelのユーザー設定のフィルターに近いものかな?
こまんどばー
めんどくさくなってきた('A`)ヴァー
これはよくわからないなら実行しないでね。
CommandBars.Add メソッド (Office)
https://msdn.microsoft.com/ja-jp/library/office/ff861773.aspx
[標準モジュール]
Option Explicit
Private Sub f()
Dim w
For Each w In Application.CommandBars
Debug.Print w.name
Next
End Sub
Sub show()
Application.CommandBars("hoge").ShowPopup
End Sub
Sub delete_menu()
Application.CommandBars("hoge").Delete
End Sub
Sub create_menu()
With Application.CommandBars.Add("hoge", msoBarPopup, False, True)
With .Controls.Add(Type:=msoControlButton)
.Caption = "aaa"
.OnAction = "'" & ThisWorkbook.name & "'!" & "hnd"
End With
End With
End Sub
Sub hnd()
MsgBox ""
End Sub