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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,884
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,020
Messages
5,834,989
Members
430,331
Latest member
Syed Yasir Hannan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top