Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default filling cells via Macro with a Vlookupfunction

Hi Y' all :)

I'm currently trying to write a macro that will fill a range of cells with
the same vlookup-formula. results should be visible in the sheet. The problem
however is that the worksheet in which the formula needs to lookup in ( the
table array) will vary daily. to solve this obstacle i created the following:

Dim currentfile As String
currentfile = ActiveWorkbook.Name
Workbooks.Open Filename:="S:\...\SAP Data\download.xls"

(the macro itself is stored in the file in which it needs to look and is
therefor already open and active( before the download.xls file is opened))

The vlookupfunction is as follows:

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-13],'[planning pharma v1.005
11-07-07_macrobouw.xls]SAP'!R2C1:R509C1,1,0)"

and its the [planning pharma v1.005 11-07-07_macrobouw.xls] that should be
replaced with the currentfile dimension
so far I've tried:
'[&currentfile&]
'[&currentfile]
'[currentfile]
'["&currentfile]

but all of these give either an error in VBA or when F8-ing myself through
it the macro want me to locate the file.

any body got a clue on how I can integrate the dim into the formula?

2nd question concers the R2C1:R509C1 section.
this table will not be limited to the current number of rows but wil expand
and therefor should be a flexible array. ( just stating R32000 is a but crude
solution, but it would work) I'm a bit lost here as well, any one got an idea?

Many thanks in advance

Azin05

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default filling cells via Macro with a Vlookupfunction

I often have problem like this especially when you are using the single
quotes. You have spaces in the file name which require the single quotes.

I would build my formula string in pieces as follows

Myformula = "=VLOOKUP(RC[-13],'[" & currentfile & "SAP'!R2C1:R509C1,1,0)"
ActiveCell.FormulaR1C1 = Myformula

"Azin05" wrote:

Hi Y' all :)

I'm currently trying to write a macro that will fill a range of cells with
the same vlookup-formula. results should be visible in the sheet. The problem
however is that the worksheet in which the formula needs to lookup in ( the
table array) will vary daily. to solve this obstacle i created the following:

Dim currentfile As String
currentfile = ActiveWorkbook.Name
Workbooks.Open Filename:="S:\...\SAP Data\download.xls"

(the macro itself is stored in the file in which it needs to look and is
therefor already open and active( before the download.xls file is opened))

The vlookupfunction is as follows:

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-13],'[planning pharma v1.005
11-07-07_macrobouw.xls]SAP'!R2C1:R509C1,1,0)"

and its the [planning pharma v1.005 11-07-07_macrobouw.xls] that should be
replaced with the currentfile dimension
so far I've tried:
'[&currentfile&]
'[&currentfile]
'[currentfile]
'["&currentfile]

but all of these give either an error in VBA or when F8-ing myself through
it the macro want me to locate the file.

any body got a clue on how I can integrate the dim into the formula?

2nd question concers the R2C1:R509C1 section.
this table will not be limited to the current number of rows but wil expand
and therefor should be a flexible array. ( just stating R32000 is a but crude
solution, but it would work) I'm a bit lost here as well, any one got an idea?

Many thanks in advance

Azin05

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default filling cells via Macro with a Vlookupfunction

HI joel,
thanks for the comment, however, i'm not using the single quotes because I
like to, only because this is the line I recorded.
If theres a different solution I'm keen to find it cause it still causes
errors.
if Myformula read "=1+5" i get 6 in the cell in the worksheet. so the
definition works.
its something else in the
"=VLOOKUP(RC[-13],'[" & currentfile & "]SAP'!R2C1:R509C1,1,0)"
thats causing the run-time error '1104': application-defined or
object-defined error

got any more good ideas?
thanks in advance

Azin05

"Joel" wrote:

I often have problem like this especially when you are using the single
quotes. You have spaces in the file name which require the single quotes.

I would build my formula string in pieces as follows

Myformula = "=VLOOKUP(RC[-13],'[" & currentfile & "SAP'!R2C1:R509C1,1,0)"
ActiveCell.FormulaR1C1 = Myformula

"Azin05" wrote:

Hi Y' all :)

I'm currently trying to write a macro that will fill a range of cells with
the same vlookup-formula. results should be visible in the sheet. The problem
however is that the worksheet in which the formula needs to lookup in ( the
table array) will vary daily. to solve this obstacle i created the following:

Dim currentfile As String
currentfile = ActiveWorkbook.Name
Workbooks.Open Filename:="S:\...\SAP Data\download.xls"

(the macro itself is stored in the file in which it needs to look and is
therefor already open and active( before the download.xls file is opened))

The vlookupfunction is as follows:

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-13],'[planning pharma v1.005
11-07-07_macrobouw.xls]SAP'!R2C1:R509C1,1,0)"

and its the [planning pharma v1.005 11-07-07_macrobouw.xls] that should be
replaced with the currentfile dimension
so far I've tried:
'[¤tfile&]
'[¤tfile]
'[currentfile]
'["¤tfile]

but all of these give either an error in VBA or when F8-ing myself through
it the macro want me to locate the file.

any body got a clue on how I can integrate the dim into the formula?

2nd question concers the R2C1:R509C1 section.
this table will not be limited to the current number of rows but wil expand
and therefor should be a flexible array. ( just stating R32000 is a but crude
solution, but it would work) I'm a bit lost here as well, any one got an idea?

Many thanks in advance

Azin05

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default filling cells via Macro with a Vlookupfunction

I ran this code below using an empty workbook "a B c".xls: and did not get
any errors. I tried a few things and finally got your error. It only occurs
if currentfile is null. If you take the code below and commentt out the
assignment of currentfile you will get the error. if currentt file is
deffine like below the code work great.

Sub test()

currentfile = "l:\temp\a b c.xls"
myf = "=VLOOKUP(RC[-13],'[" & currentfile & "]SAP'!R2C1:R509C1,1,0)"
ActiveCell.FormulaR1C1 = myf

End Sub


"Azin05" wrote:

HI joel,
thanks for the comment, however, i'm not using the single quotes because I
like to, only because this is the line I recorded.
If theres a different solution I'm keen to find it cause it still causes
errors.
if Myformula read "=1+5" i get 6 in the cell in the worksheet. so the
definition works.
its something else in the
"=VLOOKUP(RC[-13],'[" & currentfile & "]SAP'!R2C1:R509C1,1,0)"
thats causing the run-time error '1104': application-defined or
object-defined error

got any more good ideas?
thanks in advance

Azin05

"Joel" wrote:

I often have problem like this especially when you are using the single
quotes. You have spaces in the file name which require the single quotes.

I would build my formula string in pieces as follows

Myformula = "=VLOOKUP(RC[-13],'[" & currentfile & "SAP'!R2C1:R509C1,1,0)"
ActiveCell.FormulaR1C1 = Myformula

"Azin05" wrote:

Hi Y' all :)

I'm currently trying to write a macro that will fill a range of cells with
the same vlookup-formula. results should be visible in the sheet. The problem
however is that the worksheet in which the formula needs to lookup in ( the
table array) will vary daily. to solve this obstacle i created the following:

Dim currentfile As String
currentfile = ActiveWorkbook.Name
Workbooks.Open Filename:="S:\...\SAP Data\download.xls"

(the macro itself is stored in the file in which it needs to look and is
therefor already open and active( before the download.xls file is opened))

The vlookupfunction is as follows:

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-13],'[planning pharma v1.005
11-07-07_macrobouw.xls]SAP'!R2C1:R509C1,1,0)"

and its the [planning pharma v1.005 11-07-07_macrobouw.xls] that should be
replaced with the currentfile dimension
so far I've tried:
'[¤tfile&]
'[¤tfile]
'[currentfile]
'["¤tfile]

but all of these give either an error in VBA or when F8-ing myself through
it the macro want me to locate the file.

any body got a clue on how I can integrate the dim into the formula?

2nd question concers the R2C1:R509C1 section.
this table will not be limited to the current number of rows but wil expand
and therefor should be a flexible array. ( just stating R32000 is a but crude
solution, but it would work) I'm a bit lost here as well, any one got an idea?

Many thanks in advance

Azin05

Reply
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
Filling in blank cells with information from cells above it tracytracy123 Excel Discussion (Misc queries) 1 June 22nd 09 11:04 PM
Filling cells FSt1 Excel Discussion (Misc queries) 1 January 10th 08 03:39 AM
Filling cells TripleX Excel Programming 4 April 4th 07 02:32 PM
Filling cells jnf40 Excel Programming 2 September 7th 06 07:22 AM
Filling cells JohnS Excel Programming 2 September 30th 04 09:07 AM


All times are GMT +1. The time now is 11:05 AM.

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"