Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a variable Q 1

Status
Not open for further replies.

willyboy58

Technical User
May 29, 2003
86
US
I have the following procedures that make up one big procedure to print labels:

Sub HelensLabelsAll()
SelectDate
EmployeeCostCenterNumberParsing
SortCCandName
InsertBlankRow
MoveCCNumber
InsertDate
ThreeColumns
Insert2ndBlankRow
AdjustCellWidth
LeftJustify
RenameLabelSheet
End Sub

The “SelectDate” procedure is as follows:
Sub SelectDate()
Dim ReportMonth As String
ReportMonth = InputBox("Enter FULL name of month and use FOUR DIGIT" _
& " year notation. If you want to exit now" _
& "DO NOT enter anything. Just select OK" _
, "Month And Year")
If ReportMonth = "" Then
End 'kills everything
End If
End Sub

After entering the desired date, all procedures run as they should except for “InsertDate”. It does not insert the date from the “SelectDate” procedure’s variable “ReportMonth”. “InsertDate” is below:

Sub InsertDate()
Range("A1").Select
While Not IsEmpty(ActiveCell)

ActiveCell.Offset(2, 0).Select
Selection.EntireRow.Select
Selection.Insert

ActiveCell.Value = ReportMonth
DateFormat 'procedure to format date
ActiveCell.Offset(1, 0).Select
Wend
Range("A1").Select
End Sub

If I combine the two procedures and put them towards the end of “HelensLabelsAll” then I get the date to appear where I need it, but I want to enter the date at the beginning.

What am I missing?

TIA. Bill
 
Hi Bill,

ReportMonth exists only for the lifetime of the SelectDate procedure; you cannot use it later in another procedure. If you want to extend its scope make it a global variable and move the Dim statement to the top of the module before the first Sub or Function.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top