我是VBA的新手,需要以下方面的帮助:
-
从工作表中的单元格B3,B4,B5,B6,B7复制值"WORKING"
-
在工作表"TRACKING"中分别将单元格的值粘贴到范围(F2,lastrow),(G2,lastrow),(H2,最后一行),(I2,lastrow),(J2,lastrow)
*工作表“跟踪”中的“lastrow”将始终有所不同
*单元格B3,B4,B5,B6,B7将始终具有不同的值
例如
表“工作”
B3 is A1234
B4 is A
B5 is B
B6 is 1
B7 is XX
表"TRACKING" lastrow确定为4使用代码 lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
所需输出如下所示
F G H I J
(Row 1)
(row 2) A1234 A B 1 XX
(row 3) A1234 A B 1 XX
(row 4) A1234 A B 1 XX
希望有人能帮助我!谢谢!!
找到解决方案
Sub data_transpose
Dim i As Integer
Dim lastrow As Long
Dim copyRange As Range
Dim sh As Worksheet
Set copyRng = Worksheets("WORKING").Range("B3:B7")
Set sh = Worksheets("TRACKING")
lastrow = sh.Range("A2", sh.Range("A2").End(xlDown)).Rows.Count + 1
For i = 2 To lastrow
copyRng.Copy
sh.Cells(i, 6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
_SkipBlanks:=False, Transpose:=True
Next i
End Sub
2 回答
这可能对你有用
结束(xlDown).row将为您提供最后一个条目的行 .
那这个呢?
这是一个让您入门的选项: