简体   繁体   中英

Copy same non contiguous data at same cell address from multiple worksheets and paste in one master worksheet

How to copy non contiguous cells(A2,B4,D5,E1,F3) from different sheets(sheet1 to sheet 4) and paste in one master sheets ("sheet5") row by row?

The output should look in a tabular form:

cell A2 cell B4 cell D5 cell E1 cell F3 sheet 1
cell A2 cell B4 cell D5 cell E1 cell F3 sheet 2
cell A2 cell B4 cell D5 cell E1 cell F3 sheet 3
cell A2 cell B4 cell D5 cell E1 cell F3 sheet 4
Dim cel As Range, pasteRange As Range

Dim sht As Worksheet

Set pasteRange = ActiveWorkbook.Sheets("Sheet5").Range("A2")

   For Each sht In Sheets
      If sht.name <> "Sheet5" Then

        For Each cel In sht.Range("A2, B4, D5, E1, F3")

            pasteRange.Value = cel.Value

            Set pasteRange = pasteRange.Offset(0, 1)

        Next

    End If

Next

See if this helps:

Dim cel As Range, pasteRange As Range
Dim X As Long, Z As Long
Dim wb As Workbook: Set wb = ActiveWorkbook

Set pasteRange = wb.Sheets("Sheet5").Range("A2")

For X = 1 To 4
    With wb.Sheets("Sheet" & X)
        For Each cel In .Range("A2, B4, D5, E1, F3")
            pasteRange.Offset(X - 1, Y).Value = cel.Value
            Y = Y + 1
        Next cel
    End With
    Y = 0
Next X

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM