半角チルダ

ExcelVBA、その他。
覚え書きや、補足資料などのスクラップブック。
end-u(1037781)

■New DataObject

2012-05-14 21:00:00 | scrap
#ボツ回答シリーズ :)

DataObjectって意外と便利。と思ってたりする。
「ActiveSheetのA:T列の空白セル以外のデータをヨコ方向優先順でタテ1列に並べ直したい」ニーズがあったとして..
Sub test()
  Dim reg As Object
  Dim s  As String

  Set reg = CreateObject("VBScript.RegExp")
  reg.Global = True
  reg.Pattern = "¥t+"
  With ActiveSheet
    Intersect(.UsedRange, .Columns("A:T")).Copy
  End With
  With GetObject("new:1C3B4210-F441-11CE-B9EA-00AA006B1A69")
    .GetFromClipboard
    s = .GetText
    .Clear
    .SetText reg.Replace(s, vbLf)
    .PutInClipboard
  End With
  With Sheets.Add
    .Paste .Range("A1")
  End With
  Set reg = Nothing
End Sub

Comment
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする