3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

こーどの断片 φ(`д´)メモメモ

Last updated at Posted at 2015-03-08

あちこちいくからメモる(´・ω・`)

選択範囲


  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

こんなの

tbl1.PNG

挿入後

tbl2.PNG

行を消すのはカウンターあったほうがいいかな。

フィルター

オートフィルタ
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

fil.PNG

アドバンス・フィルター

対象のデータ、抽出条件、抽出結果を別々のシートでできる!


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

抽出条件

cond.PNG

よくわからない。
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

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?