0
0

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 3 years have passed since last update.

【ExcelVBA】区切り文字を指定してSplit貼り付け

Posted at

メインコード

Dim 文字列 As Variant
Dim WB As Workbook
Dim WS As Worksheet

Sub 区切り文字を指定してSplit貼り付け()
    Set WB = ActiveWorkbook
    Set WS = ActiveSheet
    
    文字列1 = Split(クリップボードからデータを取得する, vbCrLf)
    Dim 区切り文字: 区切り文字 = InputBox("区切り文字を入力して下さい")
    
    Dim i As Long, j As Long
    For i = 0 To UBound(文字列1)
        文字列2 = Split(文字列1(i), 区切り文字)
        
        For j = 0 To UBound(文字列2)
            ActiveCell.Offset(i, j).Value = 文字列2(j)
        Next
    
    Next
End Sub

Private Function クリップボードからデータを取得する()
    Dim buf As String, buf2 As String, CB As New DataObject
    With CB
        .GetFromClipboard   ''クリップボードからDataObjectにデータを取得する
        buf2 = .GetText     ''DataObjectのデータを変数に取得する
    End With
    クリップボードからデータを取得する = buf2
'    MsgBox buf2
End Function

右クリックメニューに追加/削除するコード


Sub 右クリックメニューに区切り文字を指定してSplit貼り付けを追加()
    Dim Newb
    Set Newb = Application.CommandBars("Cell").Controls.Add(Before:=1)
    With Newb
        .Caption = "区切り文字を指定してSplit貼り付け"
        .OnAction = "区切り文字を指定してSplit貼り付け"
        .BeginGroup = False
    End With
End Sub
Sub コマンド削除_区切り文字を指定してSplit貼り付け()
  CommandBars("Cell").Controls("区切り文字を指定してSplit貼り付け").Delete
End Sub

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?