excel formule

Credit for this technique goes to John 'Walkenback > http://j-walk.com/ss/excel/tips/tip82.htm

 

Private Function GetData(Path, File, Sheet, Address)

Dim Data$

Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _

Range(Address).Range("A1").Address(, , xlR1C1)

vGetData = ExecuteExcel4Macro(Data)

End Function

 

Sub GetDataDemo()

Dim FilePath$, Row&, Column&, Address$

change constants & FilePath below to suitv

'***************************************

Const FileName$ = "book1.xlsx"

Const SheetName$ = "Sheet1"

Const NumRows& = 10

Const NumColumns& = 3

FilePath = "Z:\MyFolder\"

'***************************************

DoEvents

Application.ScreenUpdating = False

If Dir(FilePath & FileName) = Empty Then

MsgBox "The file " & FileName & " was not found", , "File Doesn't Exist"

Exit Sub

End If

For Row = 1 To NumRows

For Column = 1 To NumColumns

Address = Cells(Row, Column).Address

Cells(Row, Column) = GetData(FilePath, FileName, SheetName, Address)

Columns.AutoFit

Next Column

Next Row

ActiveWindow.DisplayZeros = False

End Sub



Dodaj komentarz






Dodaj

© 2013-2024 PRV.pl
Strona została stworzona kreatorem stron w serwisie PRV.pl