Storing result of function directly in a variable instead of cell.
Dim Res as Variant 'could be an error
dim myRng as range
dim myVal as range
with worksheets("somesheetnamehere")
set myrng = .range("b50:c60)
myval = .range("a1").value
end with
res = application.vlookup(myval, myRng, 2, 0)
if iserror(res) then
'what should happen with an error?
else
msgbox res
end if
Mak wrote:
When I create code excel macros in VBA I use excel functions and I have to
store them explicitly in some cell.
for eg:
dim a as integer
cells(5,6).formula = "=vlookup(A1, B50:c60,2,0)" 'correct
a = "=vlookup(A1, B50:c60,2,0)" 'incorrect-- i need to do this thing so
that I dont have to store the formula explicitly in a cell.
plz help in this regard. I would be highly obliged.
Regards,
Mak
--
Dave Peterson
|