仅复制一个范围内的文本,仅将前三个文本粘贴到另一张纸上

时间:2018-12-31 19:58:04

标签: excel vba excel-vba

我最多有6个单元,其潜在数据来自6个不同的地方。我试图只将前三个单元格的数据传输到另一张纸上

Private Sub Transfer_Data()

Sheets("sheet1").Range("A1:A6").SpecialCells(xlCellTypeConstants, 23).copy

Sheets("sheet2").Range("A1:A3").PasteSpecial Paste:=xlPasteValues

Application.CutCopyMode = False

End Sub

这就是我所知道的,我错过了分配

3 个答案:

答案 0 :(得分:1)

这就是我要做的:

Sub Transfer_Data()

Dim i As Long, j As Long

j = 1

For i = 1 To 6
    If Sheets("Sheet1").Cells(i, 1).Value <> "" Then
        Sheets("Sheet2").Cells(j, 1).Value = Sheets("Sheet1").Cells(i, 1).Value
        j = j + 1
    End If

    If j > 3 Then Exit For
Next i

End Sub

已编辑:

Sub Transfer_Data()

    Dim i As Long, j As Long

    j = 3

    For i = 1 To 6
        If Sheets("Sheet1").Cells(i, 1).Value <> "" Then
            Sheets("Sheet2").Cells(j, 1).Value = Sheets("Sheet1").Cells(i, 1).Value
            j = j - 1
        End If

        If j = 0 Then Exit For
    Next i

End Sub

答案 1 :(得分:1)

未经测试,可能还有另一种更优雅的方法:

.subscribe((data: any) => {
    this.results = data.Search;
    console.log(this.results);

答案 2 :(得分:1)

我知道这个已经回答了,但是疯狂的单线飞机又如何呢?

Sub TransferData()
    ThisWorkbook.Sheets("Sheet2").Range("A1:A3").Value2 = WorksheetFunction.Transpose(Split(Replace$(Join(WorksheetFunction.Transpose(ThisWorkbook.Sheets("Sheet1").Range("A1:A6").Value2), ","), ",,", ","), ","))
End Sub