0

![Data Set][1]我有一个GetValues from a Closed Workbook的宏。宏工作并为我获取数据,但我缺少如何使其仅获取帐户 P 15178 的任何数据。源数据包含 5 个帐户,但我只需要获取一个帐户。帐号列在源数据的“A”列中。

这是我到目前为止所拥有的:

Sub test()


GetValuesFromAClosedWorkbook "H:\VBA", "DNAV.xlsx", "DNAV", "A1:F250"


End Sub

Sub GetValuesFromAClosedWorkbook(fPath As String, _
fName As String, sName, cellRange As String)

With ActiveSheet.Range(cellRange)
    .FormulaArray = "='" & fPath & "\[" & fName & "]" _
    & sName & "'!" & cellRange
    .Value = .Value

End With

End Sub

数据集:

4

2 回答 2

2

该答案仅基于您的数据集的图像。如果有任何延迟,您将需要调整代码。

Sub test()


    GetValuesFromAClosedWorkbook "H:\VBA", "DNAV.xlsx", "DNAV", "A1:F7" 'since your product only goes to row 7, this should be good. If your data is not sorted this way all the time, you will need a whole other solution.


End Sub

Sub GetValuesFromAClosedWorkbook(fPath As String, _
fName As String, sName, cellRange As String)

With ActiveSheet.Range(cellRange).Offset(6) 'offsetting by 6 rows should get the formula starting on cell A7
    .FormulaArray = "='" & fPath & "\[" & fName & "]" _
    & sName & "'!" & cellRange
    .Value = .Value

End With

End Sub
于 2012-08-24T15:23:25.783 回答
1

以下是您可以尝试的方法:

Sub GetValuesFromClosedWorkbook(fpath as string, fname as String, _
    sname as String, cellRange as String, criteria as String)

Activesheet.AutoFilterMode = False

With  Activesheet.Range(cellRange)
    .FormulaArray = "='" & fpath & "\[" & fname & "]" & sname & "'!" & cellRange
    .Value = .Value
    .AutoFilter  Field:=1, Criteria1:= "<>" & criteria
    .Offset(1,0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End With

Activesheet.AutoFilterMode = False

End Sub

然后像这样调用你的子:

GetValuesFromClosedWorkbook "H:\VBA", "DNAV.xlsx", "DNAV", "A1:F250", "P 15178"

未经测试,无法在我的手机中测试:) 所以我把它留给你。
完全基于您的屏幕截图。
编辑它以满足您的需要。

于 2014-01-02T08:47:19.890 回答