Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Newbie vba - How do I reference cells in another workbook

Data is transferred from another program and each transfer opens a new
workbook in Excel. I have a workbook (Main) that processes the data. I have
the workbook name in cell B4 say Book5 and part of the macro looks like this

Dim wbook

Range("b4").Select
wbook = ActiveCell.Offset(0, 0).Value
Workbooks(wbook).Activate

'Processes some data

Workbooks("Main").Activate
Range("a7").Select
ActiveCell.Offset(1, 1).Value = "=max([book5]sheet1!$b:$b)"

My question is how do I write the last line using the variable wbook
instead of the workbook name book5

Thanks

Ian


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Newbie vba - How do I reference cells in another workbook

DIM sWBook as sring
DIM WB as Workbook
DIM WS as Worksheet
DIM sFormula as String

set WS = Activesheet
sWBook = WS.Range("B4").Value
SET WB = Workbooks.Open(sWBook)

sFormula = = "=max([" & sWBook & "]sheet1!$b:$b)"

WS.Range("A7").Offset1,1).Formula = sFormula

'this line converts the formula to values
WS.Range("A7").Offset1,1).value = _
WS.Range("A7").Offset1,1).value

WB.Cloase False


HTH
Patrick Molloy
Microsoft Excel MVP


-----Original Message-----
Data is transferred from another program and each

transfer opens a new
workbook in Excel. I have a workbook (Main) that

processes the data. I have
the workbook name in cell B4 say Book5 and part of the

macro looks like this

Dim wbook

Range("b4").Select
wbook = ActiveCell.Offset(0, 0).Value
Workbooks(wbook).Activate

'Processes some data

Workbooks("Main").Activate
Range("a7").Select
ActiveCell.Offset(1, 1).Value = "=max([book5]sheet1!

$b:$b)"

My question is how do I write the last line using the

variable wbook
instead of the workbook name book5

Thanks

Ian


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Newbie vba - How do I reference cells in another workbook

Ian, Suggest a few changes to your code, as follows plus the one way of
referencing another workbook using the formula.

Dim wbook As String

wbook = Range("B4").Value & ".xls"
Workbooks(wbook).Activate

'Processes some data

Workbooks("Main.xls").Activate
Range("A7").Formula = "=max([" & wbook & "]sheet1!$B:$B)"

Cheers
Nigel

"Ian" wrote in message
...
Data is transferred from another program and each transfer opens a new
workbook in Excel. I have a workbook (Main) that processes the data. I

have
the workbook name in cell B4 say Book5 and part of the macro looks like

this

Dim wbook

Range("b4").Select
wbook = ActiveCell.Offset(0, 0).Value
Workbooks(wbook).Activate

'Processes some data

Workbooks("Main").Activate
Range("a7").Select
ActiveCell.Offset(1, 1).Value = "=max([book5]sheet1!$b:$b)"

My question is how do I write the last line using the variable wbook
instead of the workbook name book5

Thanks

Ian




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Newbie vba - How do I reference cells in another workbook

Thanks Patrick and Nigel for fixing the problem

Regards

Ian
"Ian" wrote in message
...
Data is transferred from another program and each transfer opens a new
workbook in Excel. I have a workbook (Main) that processes the data. I

have
the workbook name in cell B4 say Book5 and part of the macro looks like

this

Dim wbook

Range("b4").Select
wbook = ActiveCell.Offset(0, 0).Value
Workbooks(wbook).Activate

'Processes some data

Workbooks("Main").Activate
Range("a7").Select
ActiveCell.Offset(1, 1).Value = "=max([book5]sheet1!$b:$b)"

My question is how do I write the last line using the variable wbook
instead of the workbook name book5

Thanks

Ian




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
Help with Newbie question - Cell Reference [email protected] New Users to Excel 1 May 31st 06 02:43 AM
Can references to cells be used as part of a workbook reference blackreugen Excel Discussion (Misc queries) 1 April 18th 06 08:01 PM
Newbie Cell Reference Question... UncleRemus New Users to Excel 2 October 30th 05 12:02 PM
Newbie help with cell reference carlab68 Excel Programming 4 December 9th 03 09:58 PM
Newbie question on cell reference 2 Mfaces Excel Programming 5 December 9th 03 07:58 PM


All times are GMT +1. The time now is 02:31 AM.

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

About Us

"It's about Microsoft Excel"