VBA: Referencing a cell from a workbook into a module

mkingrey

New Member
Joined
Nov 2, 2005
Messages
49
I have a module and a workbook and need to refenerence a cell from WorkBookA in the VBA of Module1. I searched for a solution on the message board but can't find a similar question.

I need something like this:

Code:
Sub RunReport()

'This code resides in Module1 
Dim ReportDate As String

ReportDate = WorkBookA!K2.Value


End Sub
 

Some videos you may like

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,760
Office Version
  1. 365
Platform
  1. Windows
Is the module in the same project as the workbook?

If so just refer directly to the sheetname containing the cell in question:


Code:
Sub RunReport()

'This code resides in Module1
Dim ReportDate As String

ReportDate = sheets("sheet1").range("K2").Value

' ........and to test if it's working

msgbox ReportDate

End Sub


Just change the "Sheet1" ref to the name of your worksheet containing K2.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Workbook?

ReportDate = Workbooks("WorkBookA.xls").Worksheets("Sheet1").Range("K2").Value

or Worksheet?

ReportDate = Worksheets("WorkBookA").Range("K2").Value
 

Watch MrExcel Video

Forum statistics

Threads
1,118,674
Messages
5,573,598
Members
412,537
Latest member
Mohamed_5966
Top