VBA转置到另一个目标工作表

VBA转置到另一个目标工作表,vba,Vba,在下面的图片中,我有一个使用设备和属性格式化的源页面。我想创建一个宏,复制源数据并将其粘贴到目标工作表的格式中。最终,目标工作表将为空,并且仅在运行宏时填充 我是这方面的新手。我试着使用另一个堆栈溢出问题中的以下代码,但它没有达到我想要的效果 Sub ColumnCopy() Dim lastRow As Long Dim lastRow As Long Dim lastCol As Long Dim colBase As Long Dim tRow As Long Dim source As

在下面的图片中,我有一个使用设备和属性格式化的源页面。我想创建一个宏,复制源数据并将其粘贴到目标工作表的格式中。最终,目标工作表将为空,并且仅在运行宏时填充

我是这方面的新手。我试着使用另一个堆栈溢出问题中的以下代码,但它没有达到我想要的效果

Sub ColumnCopy()
Dim lastRow As Long
Dim lastRow As Long
Dim lastCol As Long
Dim colBase As Long
Dim tRow As Long
Dim source As String
Dim target As String

source = "source"       'Set your source sheet here
target = "target"       'Set the Target sheet name

tRow = 2                'Define the start row of the target sheet

'Get Last Row and Column
lastRow = Sheets(source).Range("A" & Rows.Count).End(xlUp).Row
lastCol = Sheets(source).Cells(2, Columns.Count).End(xlToLeft).Column

tRow = 2
colBase = 2

Do While colBase < lastCol
    For iRow = 2 To lastRow
        Sheets(target).Cells(tRow, 1) = Sheets(source).Cells(1, tRow)
        Sheets(target).Cells(tRow, 2) = Sheets(source).Cells(2, tRow)
        Sheets(target).Cells(tRow, 3) = Sheets(source).Cells(3, tRow)
        Sheets(target).Cells(tRow, 4) = Sheets(source).Cells(4, tRow)
        Sheets(target).Cells(tRow, 5) = Sheets(source).Cells(5, tRow)
        Sheets(target).Cells(tRow, 6) = Sheets(source).Cells(6, tRow)
        tRow = tRow + 1
    Next iRow
        colBase = colBase + 1  'Add 4 to the Column Base.  This shifts the loop over to the next Row set.
Loop
子列复制()
最后一排一样长
最后一排一样长
暗淡如长
暗淡的冷底和长的一样
昏昏欲睡
将源设置为字符串
将目标变暗为字符串
source=“source”在此处设置源工作表
target=“target”'设置目标工作表名称
tRow=2'定义目标工作表的起始行
'获取最后一行和最后一列
lastRow=工作表(源).Range(“A”&Rows.Count).End(xlUp).Row
lastCol=工作表(源)。单元格(2,Columns.Count)。结束(xlToLeft)。列
tRow=2
colBase=2
colBase
端接头

谢谢,
MJ

可能这个链接会给你一些想法:可能这个链接会给你一些想法: