Hi there,
I have this code which extracts the values I want from the spreadsheet I want, however there is only one problem - hopefully an easy fix.
This extracts the data from rows 5 to 28 and columns 26 to 36, but inputs these values into my sheet in the same place.
I would like the macro to be able to do what it is doing, but then instead of getting values and putting them in from 5,26 I want it to start pasting into cell B4 (or 4,2).
Is there an easy way to do this?
Thanks in advance,
sn281
I have this code which extracts the values I want from the spreadsheet I want, however there is only one problem - hopefully an easy fix.
This extracts the data from rows 5 to 28 and columns 26 to 36, but inputs these values into my sheet in the same place.
I would like the macro to be able to do what it is doing, but then instead of getting values and putting them in from 5,26 I want it to start pasting into cell B4 (or 4,2).
Is there an easy way to do this?
Thanks in advance,
sn281
Code:
Private Function GetValue(path, file, sheet, ref)
Dim arg As String
' Make sure the file exists
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
' Create the argument
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("A1").Address(, , xlR1C1)
' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function
Sub GetValue2()
Application.Calculation = xlCalculationManual
p = "O:\Power\PowerPnL"
f = "PowerPositions-v6.0.xlsm"
s = "Last Prices"
Application.ScreenUpdating = False
For r = 5 To 28
For c = 26 To 36
a = Cells(r, c).Address
Cells(r, c) = GetValue(p, f, s, a)
Next c
Next r
Application.ScreenUpdating = True
End Sub