setting up a public variable

grunschlange

New Member
Joined
Sep 12, 2009
Messages
13
Good morning.

I have files with macros that list overdue cases in our offices. We have 6 offices--each handles what we code as "F" cases and "A" cases. So, for example, Office 1 has a file for overdue "F" cases and one for overdue "A" cases, therefore totalling 12 files that I am working with.

A sample of the macro (taken from an "F" case file) is below:

Sheets("F Cases").Select
Range("A1").Select
Dim FilterRange As Range
Dim CopyRange As Range
Dim D As Date
Set FilterRange = Range("M1:M5000") 'Header in row
Set CopyRange = Range("A1:N5000")
D = InputBox("Enter the last day of the current report month (m/d/yyyy).", "Date Selection")
FilterRange.AutoFilter Field:=1, Criteria1:="<" & D
CopyRange.SpecialCells(xlCellTypeVisible).Copy _
Destination:=Worksheets("Overdue F Reviews").Range("A3")
Application.CutCopyMode = False
Sheets("F Cases").Select
Selection.AutoFilter
Application.Goto Reference:="R1C1"
Sheets("Overdue F Reviews").Select
Application.Goto Reference:="R1C1"

The input box therefore pops up 12 times when I run all office files each month. I believe I saw once that a public variable could be used once and it would be read in the code for all modules. I would like to input the date once and each file then runs with that same date variable. How do I set this up? Do I declare the public variable in a regular module, or is there a special place to put it? I would like to use that same variable "D" for date, if possible.

If it helps any, each office has it's own folder in my C:\ drive (i.e. a folder entitled "Office 1", "Office 2", etc.). Within each folder are the lists (i.e. one entitled "Office1OverdueFReviews.xls", "Office1OverdueAReviews.xls", "Office2OverdueFReviews.xls", etc.).

Thanks for any help you can give.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

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