要粘贴到另一个工作表的动态数据范围

时间:2018-04-23 05:03:24

标签: excel vba excel-vba

我想将Sheet 1 A列中的所有数据复制到Sheet 2

问题是我想将数据粘贴到表2中,但是从单元格A13开始

示例表1 A2要粘贴到表2单元格A13中的值

这是我的代码,它将A列表1的值粘贴到A列表但是我无法更改起始单元格

Sub test1()
    ' test1 Macro

    Application.ScreenUpdating = False

    Dim s1 As Excel.Worksheet
    Dim s2 As Excel.Worksheet
    Dim iLastCellS2 As Excel.Range
    Dim iLastRowS1 As Long

    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")

    ' get last row number of A in Sheet1
    iLastRowS1 = s1.Cells(s1.Rows.Count, "A").End(xlUp).Row

    ' get last AVAILABLE cell to past into
    Set iLastCellS2 = s2.Cells(s2.Rows.Count, "A").End(xlUp).Offset(1, 0)

    'copy&paste into sheet2
    s1.Range("A2", s1.Cells(iLastRowS1, "A")).Copy iLastCellS2

    Application.ScreenUpdating = True
End Sub

谢谢

2 个答案:

答案 0 :(得分:0)

如果您想要始终直接粘贴到A13(非动态),那么:

  s1.Range("A2", s1.Cells(iLastRowS1, "A")).Copy s2.Cells(13,"A")

如果你总是希望它至少从A13开始:

Set iLastCellS2 = IIf(s2.Cells(s2.Rows.Count, "A").End(xlUp).Row < 13, s2.Cells(13, "A"), s2.Cells(s2.Rows.Count, "A").End(xlUp).Offset(1, 0))
s1.Range("A2", s1.Cells(iLastRowS1, "A")).Copy iLastCellS2

答案 1 :(得分:0)

试试这个:

Object.values(res).forEach(({ lat, lng }) => {
  const marker = new google.maps.Marker({
    position: new google.maps.LatLng(lat, lng),
    map: map
  });
});