Public Variables

J

Jerry McNabb

I have the floolwing macro which is always run as the first procedure in my
application:

Option Explicit
Public intRecordRow As Integer
Public intRecordCol As Integer


Sub Clear()

Sheets("Columns").Select
Range("A1:I9").Select
Selection.ClearContents
Selection.Interior.ColorIndex = 15

Range("L1:AQ29").Select
Selection.Interior.ColorIndex = 37

Range("J32:AJ34").Select
Selection.ClearContents

Sheets("Rows").Select
Range("A1:I9").Select
Selection.Interior.ColorIndex = 15
Range("L1:AQ29").Select
Selection.Interior.ColorIndex = 37
Sheets("Areas").Select
Range("A1:I9").Select
Selection.Interior.ColorIndex = 15
Range("L1:AQ29").Select
Selection.Interior.ColorIndex = 37

intRecordRow = 32
intRecordCol = 11

End Sub

'
This seems to work just fine and intRecordRow is 32 and intRecordDol is 11.
I then run the following module:

Sub Load()

Dim intColor As Integer
Dim strCell As String
Dim strValue As String
Dim strRef As String

intColor = Worksheets("Columns").Cells(14, 2).Interior.ColorIndex
strCell = Application.InputBox(prompt:="Select a cell", Type:=2)

strValue = Application.InputBox(prompt:=("Enter a value for " &
strCell), Type:=1)

Worksheets("Columns").Range(strCell).Value = strValue
Worksheets("Columns").Range(strCell).Interior.ColorIndex = intColor
Worksheets("Rows").Range(strCell).Interior.ColorIndex = intColor
Worksheets("Areas").Range(strCell).Interior.ColorIndex = intColor

strRef = Worksheets("ColumnList").Range(strCell).Value
Worksheets("Columns").Range(strRef).Interior.ColorIndex = intColor

strRef = Worksheets("RowList").Range(strCell).Value
Worksheets("Rows").Range(strRef).Interior.ColorIndex = intColor

strRef = Worksheets("AreaList").Range(strCell).Value
Worksheets("Areas").Range(strRef).Interior.ColorIndex = intColor

Worksheets("Columns").Range(intRecordCol, intRecordRow).Value = strCell
intRecordCol = intRecordCol + 1
If intRecordCol > 37 Then
intRecordRow = intRecordRow + 1
intRecordCol = 11
End If

End Sub

By the time I reach the references to the public variables, both have been
set to zero.
' Clear Macro
' Clear for a new game
'
' Keyboard Shortcut: Ctrl+d
'

Sheets("Columns").Select
Range("A1:I9").Select
Selection.ClearContents
Selection.Interior.ColorIndex = 15

Range("L1:AQ29").Select
Selection.Interior.ColorIndex = 37

Range("J32:AJ34").Select
Selection.ClearContents

Sheets("Rows").Select
Range("A1:I9").Select
Selection.Interior.ColorIndex = 15
Range("L1:AQ29").Select
Selection.Interior.ColorIndex = 37
Sheets("Areas").Select
Range("A1:I9").Select
Selection.Interior.ColorIndex = 15
Range("L1:AQ29").Select
Selection.Interior.ColorIndex = 37

intRecordRow = 32
intRecordCol = 11

End Sub

By the time I try to use the public variables, both have been set to zero.
What happened? Can someone please help? Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top