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?

Posted at

Sub CopyQueryTableToPlainSheet()
Dim srcWs As Worksheet
Dim destWs As Worksheet
Dim lo As ListObject
Dim srcRange As Range
Dim destStartCell As Range

' 1つ目のシートに読み込まれたテーブルがあると仮定
Set srcWs = ThisWorkbook.Sheets(1)
Set destWs = ThisWorkbook.Sheets.Add(After:=srcWs)
destWs.Name = "値だけコピー"

' 対象のテーブルを取得
If srcWs.ListObjects.Count = 0 Then
    MsgBox "テーブル(Power Queryの読み込み結果)が見つかりません。", vbExclamation
    Exit Sub
End If

Set lo = srcWs.ListObjects(1)
Set srcRange = lo.Range
Set destStartCell = destWs.Range("A1")

' 値と書式をコピー
destStartCell.Resize(srcRange.Rows.Count, srcRange.Columns.Count).Value = srcRange.Value
destStartCell.Resize(srcRange.Rows.Count, srcRange.Columns.Count).NumberFormat = srcRange.NumberFormat

' オプション:読み込み元のテーブルを削除(必要なら)
' lo.Delete

MsgBox "値と書式をコピーしました(" & destWs.Name & ")", vbInformation

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?