Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default How to refer to a cell from another workbook in VBA


Hi,
I want to check the date in 5 cells belongings to 5 different worksheets of
5 workbooks to make sure they are all the same.
E.g: Cell A1 in worksheet "StoreA" of workbook "Material"
Cell A1 in worksheet "StoreB" of workbook "Tools"
Cell A1 in worksheet "StoreC" of workbook "WIP"
Cell A1 in worksheet "StoreD" of workbook "Goods"

Pls advise me a VBA code to solve this.

Thanks so much
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default How to refer to a cell from another workbook in VBA


If the workbooks will be open at the time:

workbooks("Material").worksheets("StoreA").range(" A1").value gets the value

"diepvic" wrote:

Hi,
I want to check the date in 5 cells belongings to 5 different worksheets of
5 workbooks to make sure they are all the same.
E.g: Cell A1 in worksheet "StoreA" of workbook "Material"
Cell A1 in worksheet "StoreB" of workbook "Tools"
Cell A1 in worksheet "StoreC" of workbook "WIP"
Cell A1 in worksheet "StoreD" of workbook "Goods"

Pls advise me a VBA code to solve this.

Thanks so much

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default How to refer to a cell from another workbook in VBA


Workbooks("Material").Worksheets("StoreA").Range(" A1")
etc.

Regards,
Stefi

€˛diepvic€¯ ezt Ć*rta:

Hi,
I want to check the date in 5 cells belongings to 5 different worksheets of
5 workbooks to make sure they are all the same.
E.g: Cell A1 in worksheet "StoreA" of workbook "Material"
Cell A1 in worksheet "StoreB" of workbook "Tools"
Cell A1 in worksheet "StoreC" of workbook "WIP"
Cell A1 in worksheet "StoreD" of workbook "Goods"

Pls advise me a VBA code to solve this.

Thanks so much

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default How to refer to a cell from another workbook in VBA


It is always better to create an object for referencing..

Dim wbBook As Workbook
Dim wsSheet As Worksheet

'To reference a open workbook (unsaved)
Set wbBook = Workbooks("Book1")

'To reference a open workbook (already saved)
Set wbBook = Workbooks("Book1.xls")

'To reference a work sheet
Set wsSheet = wbBook.Worksheets("Sheet1")

'To access cell A1 of book1 Sheet1
wsSheet.Range("A1")

If this post helps click Yes
---------------
Jacob Skaria


"diepvic" wrote:

Hi,
I want to check the date in 5 cells belongings to 5 different worksheets of
5 workbooks to make sure they are all the same.
E.g: Cell A1 in worksheet "StoreA" of workbook "Material"
Cell A1 in worksheet "StoreB" of workbook "Tools"
Cell A1 in worksheet "StoreC" of workbook "WIP"
Cell A1 in worksheet "StoreD" of workbook "Goods"

Pls advise me a VBA code to solve this.

Thanks so much

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default How to refer to a cell from another workbook in VBA


Change the Workbook names and sheetname to suit.
dt1 = Workbooks("Book3").Worksheets("Sheet1").Range("A1" )
dt2 = Workbooks("Book3").Worksheets("Sheet2").Range("A1" )
dt3 = Workbooks("Book3").Worksheets("Sheet3").Range("A1" )
dt4 = Workbooks("Book3").Worksheets("Sheet4").Range("A1" )
dt5 = Workbooks("Book3").Worksheets("Sheet5").Range("A1" )

If dt1 = dt2 And dt1 = dt3 And dt1 = dt4 And dt1 = dt5 Then
MsgBox "The dates are same"
'your code
Else
'your code
End If

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

It is always better to create an object for referencing..

Dim wbBook As Workbook
Dim wsSheet As Worksheet

'To reference a open workbook (unsaved)
Set wbBook = Workbooks("Book1")

'To reference a open workbook (already saved)
Set wbBook = Workbooks("Book1.xls")

'To reference a work sheet
Set wsSheet = wbBook.Worksheets("Sheet1")

'To access cell A1 of book1 Sheet1
wsSheet.Range("A1")

If this post helps click Yes
---------------
Jacob Skaria


"diepvic" wrote:

Hi,
I want to check the date in 5 cells belongings to 5 different worksheets of
5 workbooks to make sure they are all the same.
E.g: Cell A1 in worksheet "StoreA" of workbook "Material"
Cell A1 in worksheet "StoreB" of workbook "Tools"
Cell A1 in worksheet "StoreC" of workbook "WIP"
Cell A1 in worksheet "StoreD" of workbook "Goods"

Pls advise me a VBA code to solve this.

Thanks so much

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 Refer to Another Excel Workbook hon123456 Excel Programming 1 January 4th 08 09:33 AM
Refer to workbook Arne Hegefors Excel Programming 1 November 15th 07 09:20 AM
how do I refer a cell to workbook name not worksheet esparzaone Excel Discussion (Misc queries) 2 October 2nd 07 09:18 PM
How to refer to the specified sheet in the workbook? Jack Excel Programming 1 September 19th 07 11:11 PM
When writing a macro in excel workbook, how do I refer to ea cell Diana Bartz Excel Programming 1 July 7th 05 09:51 PM


All times are GMT +1. The time now is 10:02 PM.

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"