VBA代码从多个spredsheets中提取最大数据

时间:2015-09-04 12:29:32

标签: excel-vba vba excel

该工作簿有大约50个具有唯一名称的spredsheets。每个电子表格都有数据直到列“F”。 我想将电子表格名称拉到一列,将每个电子表格中“C”列的最大数据拉到下一列,但我知道最大数据来自特定电子表格。

1 个答案:

答案 0 :(得分:1)

这是怎么回事:

Sub get_Max()
Dim mainWS As Worksheet, ws As Worksheet
Dim rng As Range, cel As Range
Dim i%

Set mainWS = Sheets("Sheet1") ' Change this to meet your criteria. This is where the data will go

For i = Sheets.Count To 0 Step -1
    If Worksheets(i).Name = mainWS.Name Then Exit For
    ' Let's first list the sheet names in Column A of our mainWS
    mainWS.Cells(i, 1).Value = Sheets(i).Name
    ' Then get the max value from column C ('3').
    mainWS.Cells(i, 2).Value = WorksheetFunction.Max(Sheets(i).Range(Sheets(i).Columns(3), Sheets(i).Columns(3)))
Next i

End Sub