VBA:从多个工作簿/工作表中提取值

时间:2015-07-24 20:33:03

标签: excel vba excel-vba

我需要一个宏来从工作簿的C列中获取不同的值,并在同一工作表,新工作表或新工作簿中编译唯一的值。

例如,Col.C可能包含50行的值' Excel2'和Word2'的150个值,我只需要将Excel2和Word2显示在某处,只需一次。也许在新的工作表/工作簿中说明C列标题。

到目前为止,这是我的宏,可能正在改变' lrng.formula'部分会有所帮助:

Sub Calculationallsheetsv2()
'Calculation all sheets, even when there is only headers

Dim xrng As Range, lrw As Long, lrng As Range, i As Long
Dim LstCo As Long, ws As Worksheet

With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With

For Each ws In ActiveWorkbook.Worksheets
    With ws
        If Not Application.WorksheetFunction.CountA(.Cells) = 0 Then

            LstCo = .Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
            For i = 1 To LstCo
                With .Columns(i)
                    .TextToColumns Destination:=.Cells(1, 1), DataType:=xlDelimited, TrailingMinusNumbers:=True
                End With
            Next

            lrw = .Columns("A:Y").Find("*", , xlValues, , xlRows, xlPrevious).Row
            If lrw = 1 Then lrw = 2
            Set lrng = .Range("A" & lrw + 2)

            With .Range("A2:A" & lrw)
                lrng.Formula = "=COUNTA(" & .Address(0, 0) & ")/ROWS(" & .Address(0, 0) & ")"
            End With

            Set xrng = .Range(lrng, .Cells(lrng.Row, LstCo))

            lrng.AutoFill xrng, Type:=xlFillDefault
            xrng.Style = "Percent"
        End If
    End With
Next

With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
    Application.CalculateFull

End With

End Sub

1 个答案:

答案 0 :(得分:0)

您可以使用Excel的内置$(".btn-disapear").click(function() { $(this).closest(".panel").fadeOut(400); }); 功能来执行此操作。例如,这会抓取AdvancedFilter上的C列中的唯一值,并将其放在Sheet1上的C列中:

Sheet3