LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Inserting VLookup using VBA - Problems concatinating contents of cell & variable

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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting rows while keeping cell contents the same JDNETTC Excel Discussion (Misc queries) 4 January 30th 08 11:34 PM
Concatinating text plus cell containing date Lori Excel Worksheet Functions 2 October 17th 07 08:06 PM
Taking contents of a cell an inserting them into a phrase. dnguyen411 Excel Discussion (Misc queries) 1 December 13th 06 04:29 AM
Problems using a variable as a Table_Array in VLOOKUP Jeff Lowenstein Excel Worksheet Functions 1 July 16th 05 02:12 AM
Inserting Cell Contents into a header Darin Kramer Excel Programming 3 December 13th 04 02:27 PM


All times are GMT +1. The time now is 08:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"