Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Match and VLOOKUP from open workbook, storing values in Active wkb

I have a macro which opens workbooks and checks for the existance of Sheet1.
If sheet 1 is there, I want to populate other fields in the active workbook
from the open workbook.

I have the following equations I want to use:

Range("BW2").Select
ActiveCell.FormulaR1C1 = _
"=MATCH(RC[-2],'[Book1.xls]Sheet1'!R33)"
Range("BX2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(R1C,'[Book1.xls]Sheet1'!R1:R50,RC75,FALSE)"
Range("BY2").Select


1) Is there a more elegant way to write these equations?
2) How do I ensure that I get the value in the active cell of the active
workbook, not the equation?
3) Book1.xls is from column G of the workbook. I have a For/Next loop
going from the first to the last book I'm evaluating with the counter being
i.

How would I rewrite these equations to get what I want?

Thanks in advance for your assistance.

Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Match and VLOOKUP from open workbook, storing values in Active wkb

Dim cell as Range, eq1 as String, eq2 as String
Dim eq1a as String, eq1b as String
Dim bk as Workbook
eq1 = "=MATCH(RC[-2],'[ZZZ]Sheet1'!R33)"
eq2 = ""=VLOOKUP(R1C,'[ZZZ]Sheet1'!R1:R50,RC75,FALSE)"

With ThisWorkbook.worksheets("Data")
for each cell in .Range("G2:G20")
set bk = Workbook.Open(cell)
eq1a = replace(eq1,"ZZZ",bk.name)
eq2a = replace(eq2,"ZZZ",bk.Name)
.cells(cell.row,"BW").Formula = eq1a
.cells(cell.row,"BW").Formula = .cells(cell.row,"BW").Value
.cells(cell.row,"BX").Formula = eq2a
.cells(cell.row,"BX").Formula = .cells(cell.row,"BX").Value
bk.close SaveChanges:=False
Next
End With

I understood you to want to replace the formula with the value returned by
the formula. If not, then take out lines like

.cells(cell.row,"BW").Formula = .cells(cell.row,"BW").Value

--
Regards,
Tom Ogilvy

"Barb Reinhardt" wrote in message
...
I have a macro which opens workbooks and checks for the existance of

Sheet1.
If sheet 1 is there, I want to populate other fields in the active

workbook
from the open workbook.

I have the following equations I want to use:

Range("BW2").Select
ActiveCell.FormulaR1C1 = _
"=MATCH(RC[-2],'[Book1.xls]Sheet1'!R33)"
Range("BX2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(R1C,'[Book1.xls]Sheet1'!R1:R50,RC75,FALSE)"
Range("BY2").Select


1) Is there a more elegant way to write these equations?
2) How do I ensure that I get the value in the active cell of the active
workbook, not the equation?
3) Book1.xls is from column G of the workbook. I have a For/Next loop
going from the first to the last book I'm evaluating with the counter

being
i.

How would I rewrite these equations to get what I want?

Thanks in advance for your assistance.

Barb Reinhardt



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
how to open a workbook per active window Jackie[_2_] Excel Discussion (Misc queries) 1 August 19th 08 11:13 PM
Why does a new Excel Workbook open with IV1 as the active cell? pjwing Excel Discussion (Misc queries) 1 July 3rd 07 11:26 PM
Making an open workbook active Jay Oken Excel Programming 1 March 19th 05 11:44 PM
Get range value active workbook on open add-in Ajtb Excel Programming 1 February 11th 05 01:52 PM
How do I make an open workbook the active workbook Don Guillett[_4_] Excel Programming 0 December 30th 03 04:28 PM


All times are GMT +1. The time now is 05:40 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"