人力検索はてな
モバイル版を表示しています。PC版はこちら
i-mobile

エクセルVBAでクリップボードへのコピー操作がわからなくて困っています。
下記のコードを書いて1つのデータをコピーするまではできていますが、
処理した dataの配列を コピーする方法がわからなくて困っています。
何か良い方法はありませんか?よろしくお願い致します。

Sub number_tran()
Dim i As Integer
Dim data(5, 11) As Double
Dim intYLine As Integer, intXLine As Integer
Dim objFirstFindCell As String
Dim objFindCell As Object, clipboardData As Object

Set clipboardData = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

Worksheets(1).Activate
Set objFindCell = Worksheets(1).Cells.Find("apple", LookAt:=xlWhole)

If Not objFindCell Is Nothing Then
objFirstFindCell = objFindCell.Address
i = 1
Do
intYLine = objFindCell.Cells.Row
intXLine = objFindCell.Cells.Column
data(1, i) = Cells(intYLine, intXLine + 1).Value
data(2, i) = Cells(intYLine + 1, intXLine + 1).Value
data(3, i) = Cells(intYLine + 2, intXLine + 1).Value
i = i + 1
Set objFindCell = Cells.FindNext(objFindCell)
Loop Until objFindCell.Address = objFirstFindCell
End If

With clipboardData
.setText data(1, 1)
.PutInClipboard
End With
End Sub

●質問者: pochi1234
●カテゴリ:コンピュータ
○ 状態 :終了
└ 回答数 : 1/1件

▽最新の回答へ

1 ● きゃづみぃ
●100ポイント ベストアンサー

取得した値をエクセルに貼り付けやすいようにしてみました。

Sub number_tran()
Dim i As Integer
Dim data(5, 11) As Double
Dim intYLine As Integer, intXLine As Integer
Dim objFirstFindCell As String
Dim objFindCell As Object, clipboardData As Object
Dim k As Integer
Dim s As String

Set clipboardData = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

Worksheets(1).Activate
Set objFindCell = Worksheets(1).Cells.Find("apple", LookAt:=xlWhole)

If Not objFindCell Is Nothing Then
 objFirstFindCell = objFindCell.Address
 i = 1
 Do
 intYLine = objFindCell.Cells.Row
 intXLine = objFindCell.Cells.Column
 data(1, i) = Cells(intYLine, intXLine + 1).Value
 data(2, i) = Cells(intYLine + 1, intXLine + 1).Value
 data(3, i) = Cells(intYLine + 2, intXLine + 1).Value
 i = i + 1
 Set objFindCell = Cells.FindNext(objFindCell)
 Loop Until objFindCell.Address = objFirstFindCell

 s = ""
 For k = 1 To i - 1
 s = s & data(1, k) & Chr(9)
 s = s & data(2, k) & Chr(9)
 If k = i - 1 Then
 s = s & data(3, k)
 Else
 s = s & data(3, k) & Chr(9)
 End If
 Next k

 With clipboardData
 .setText s
 .PutInClipboard
 End With
End If


End Sub
◎質問者からの返答

質問の趣旨を間違えてしまいました。申し訳ありません。

エクセル等で セルを複数選択して貼り付けるのは簡単ですが、

配列でデータの並び替え変換をしてから、

クリップボードにコピーしてしたのち、

複数のセルを手動で貼り付けるような使用方法を考えています。

関連質問

●質問をもっと探す●



0.人力検索はてなトップ
8.このページを友達に紹介
9.このページの先頭へ
対応機種一覧
お問い合わせ
ヘルプ/お知らせ
ログイン
無料ユーザー登録
はてなトップ