将值从工作表复制到其他工作表仅复制到空白单元格

时间:2018-09-05 06:37:05

标签: excel vba

我是VBA和这个网站上的新手。我找到并修改了此代码,以满足我的需要,但是它仅复制了“ TABEL”表(列A)的空白单元格中列A(表“ Vectori”)的第一行,我想复制列A中的所有值(“ Vectori”工作表),而不仅仅是一个。

Sub test()
    Dim myvalue As String
    Dim lastrow As Long

    lastrow = Rows(Rows.count).End(xlUp).Row

    Worksheets("Vectori").Select

    myvalue = Range("A2").value

    Worksheets("TABEL").Select

    Range("A2").Select

    'go to first blank cell

    ActiveCell.End(xlDown).Select

    ActiveCell.Offset(1, 0).Select

    'write variable values into this blank row

    ActiveCell.value = myvalue


    Range(ActiveCell.Offset(-1, 0), ActiveCell.Offset(-1, 1)).copy

    ActiveCell.PasteSpecial xlPasteFormats

    Application.CutCopyMode = False
End Sub

2 个答案:

答案 0 :(得分:0)

只需增加范围即可满足您的需求。

替换:

Range("A2")

使用:

Range("A2:Z100")

只需选择覆盖整个数据的范围即可。

答案 1 :(得分:0)

我解决了:)

Sub test()

Dim thisarray As Variant
Dim lastrow As Long
Dim index As Integer
index = 1

lastrow = Cells(Rows.count, 1).End(xlUp).Row
thisarray = Worksheets("Vectori").Range("A2:A" & lastrow).value

While index <= UBound(thisarray)
        Worksheets("TABEL").Select
        Range("A2").Select
        ActiveCell.End(xlDown).Select
        ActiveCell.Offset(1, 0).Select
        ActiveCell.value = thisarray(index, 1)
 index = index + 1
Wend

End Sub

祝你有美好的一天!

相关问题