Defining Workbooks / Worksheets

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,533
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I go back and forth between several different workbooks and worksheets in the course of my VB project execution.

Is their a simple way of defining the different destinations rather than always having to type Workbooks("Workbook1").Worksheets("Sheet") ?

Jenn
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi Jenn,

One option is to use Worksheet Object variables:

Code:
Dim wstA as Worksheet
Dim wstB as Worksheet
 
Set wstA = Workbooks("Workbook1").Worksheets("Sheet1")
Set wstB = Workbooks("Workbook2").Worksheets("Sheet3")

From there on, you can refer to ranges (etc...) on those worksheets by using:
Code:
wstA.Range("A1").Value = 1
wstB.Range("E2").Value = "Hello"

etc...

Hope that helps...
 
Upvote 0
Will I have to define these in all my individual subs in which they are accessed, or is there a place to apply them globally?
 
Upvote 0
Do these subs call each other (ie. They all run together in a sequence), or do they run at separate times? Are they all contained in the same code module, or separate code modules?
 
Upvote 0
Some subs are called from each other, others are called when needed. Subs are scattered amongst a few modules.
 
Upvote 0

Forum statistics

Threads
1,196,487
Messages
6,015,495
Members
441,898
Latest member
kofafa

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
Back
Top