工作表中的单元格值到工作表中的一列

时间:2014-07-17 17:31:33

标签: excel vba

我试图运行一个宏,以便对于工作表中的每个单元格(所有工作表的范围都相同),它将列在不同范围的现有工作表的列中。我有宏的阅读部分,我不知道如何列出现有工作表中工作表中的每个值:

Sub wstocolumn() 'Saves the excel print area to a PDF file

    Dim fp As String
    Dim wb As Workbook
    Dim rng As Range
    Dim intWS As Integer

    Set wb = ActiveWorkbook
    Worksheets("Sheet4").Activate
    For intWS = 1 To wb.Worksheets.Count
        With wb.Worksheets(intWS)
            Set rng = .Range("A1")
            Set Worksheets("Sheet4").Range("A4:A10") = rng '<----- this is where I want each value_ _from the worksheets
        End With
    Next intWS
End Sub

1 个答案:

答案 0 :(得分:1)

也许是这样的:

Sub tgr()

    Dim ws As Worksheet
    Dim arrCells() As Variant
    Dim i As Long

    ReDim arrCells(1 To ActiveWorkbook.Sheets.Count)

    For Each ws In ActiveWorkbook.Sheets
        i = i + 1
        arrCells(i) = ws.Range("A1").Value
    Next ws

    Sheets("Sheet4").Range("A4").Resize(i).Value = Application.Transpose(arrCells)

End Sub