S
scott_smith
Hi,
I'm trying to insert a Vlookup into a cell based on variables that are
collceted via a user form.
Only problem is, for the "Else" part of the the below "If" statement I
get a "Run-time error '1004': Application-defined or object-defined
error".
I think it's becuase it doesn't like the concatenation of the FundCode
and Series variables, but I can't work out how to fix it.
The first part of the "If" statement works when the Fundcode variable
is passed as a string, but in the latter case when Fundcode is passed
as a cell address it doesn't work.
Can anyone give me any help or advice?
Thanks in advance,
Scott
-----------------
Sub InsertFundPrice(FundCode As Variant, Series As String, Pricedate
As Date)
Dim PriceMonth, PriceYear As String
PriceMonth = Left(MonthName(Month(Pricedate)), 3)
PriceYear = Right(Pricedate, 4)
If Len(FundCode) <= 2 Then
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(""" & FundCode & Series & """,'J:\RESTRICT
\Performance\Bulletin\Fund Prices\" & PriceYear & "\" & PriceMonth & "\
[fund prices 01" & PriceMonth & PriceYear & ".xls]Summary'!
R2C4:R2000C5,2,FALSE)"
Else
VTarget = FundCode & " & " & Series
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(" & VTarget & ",'J:\RESTRICT\Performance\Bulletin
\Fund Prices\" & PriceYear & "\" & PriceMonth & "\[fund prices 01" &
PriceMonth & PriceYear & ".xls]Summary'!R2C4:R2000C5,2,FALSE)"
End If
End Sub
I'm trying to insert a Vlookup into a cell based on variables that are
collceted via a user form.
Only problem is, for the "Else" part of the the below "If" statement I
get a "Run-time error '1004': Application-defined or object-defined
error".
I think it's becuase it doesn't like the concatenation of the FundCode
and Series variables, but I can't work out how to fix it.
The first part of the "If" statement works when the Fundcode variable
is passed as a string, but in the latter case when Fundcode is passed
as a cell address it doesn't work.
Can anyone give me any help or advice?
Thanks in advance,
Scott
-----------------
Sub InsertFundPrice(FundCode As Variant, Series As String, Pricedate
As Date)
Dim PriceMonth, PriceYear As String
PriceMonth = Left(MonthName(Month(Pricedate)), 3)
PriceYear = Right(Pricedate, 4)
If Len(FundCode) <= 2 Then
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(""" & FundCode & Series & """,'J:\RESTRICT
\Performance\Bulletin\Fund Prices\" & PriceYear & "\" & PriceMonth & "\
[fund prices 01" & PriceMonth & PriceYear & ".xls]Summary'!
R2C4:R2000C5,2,FALSE)"
Else
VTarget = FundCode & " & " & Series
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(" & VTarget & ",'J:\RESTRICT\Performance\Bulletin
\Fund Prices\" & PriceYear & "\" & PriceMonth & "\[fund prices 01" &
PriceMonth & PriceYear & ".xls]Summary'!R2C4:R2000C5,2,FALSE)"
End If
End Sub