Glitch5618
Board Regular
- Joined
- Nov 6, 2015
- Messages
- 105
Using excel 2007.
I'm trying to load an array into a worksheet, the array in question is declared as public within one module and is later called in a second module where the error occurs. The line throwing the error is highlighted in red. Array in blue.
First module:
Second Module calling AgentQuestionArray:
Can anyone explain why this is giving me an error? I'm completely confused because the Destination range works in all my other code, however it is contained within the same module that the arrays are declared as public. Although my understanding is that if its public it should be accessible to all modules or userforms in a project. I could really use help with this and an explanation of how to fix this, since I need to be able to load the array to a worksheet to filter the dates contained in the data.
I'm trying to load an array into a worksheet, the array in question is declared as public within one module and is later called in a second module where the error occurs. The line throwing the error is highlighted in red. Array in blue.
First module:
Rich (BB code):
Option Explicit
Public d As DataBox
Public f As UserForm
Public AgentQuestionArray() As Variant
Public frmloaded As Boolean
Public Sub GetAgentQuestion()
'Prevents screen flickering
Application.ScreenUpdating = False
'PURPOSE: Searches for all all instances of agent name in question data and displays array in listbox
Set d = DataBox
Set f = UserForm
Dim fnd As String, FirstFound As String
Dim FoundCell As Range, Rng As Range
Dim myRange As Range, LastCell As Range
Worksheets("Question Data").Activate
'Sorts the Agent column to allow re-sizing of rng data range
With ActiveWorkbook.Worksheets("Question Data")
.Range("A1:A" & .Range("A" & Rows.Count).End(xlUp).Row).Sort Key1:=.Range("A2"), Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End With
'Search value
fnd = f.cboOption.Value
Set myRange = ActiveSheet.Range("A:A")
Set LastCell = myRange.Cells(myRange.Cells.Count)
Set FoundCell = myRange.Find(what:=fnd, after:=LastCell)
'Test to see if anything was found
If Not FoundCell Is Nothing Then
FirstFound = FoundCell.Address
Else
GoTo NothingFound
End If
Set Rng = FoundCell
'Loop until cycled through all unique finds
Do Until FoundCell Is Nothing
'Find next cell with fnd valuem
Set FoundCell = myRange.FindNext(after:=FoundCell)
'Add found cell to rng range variable
Set Rng = Union(Rng, FoundCell)
'Test to see if cycled through to first found cell
If FoundCell.Address = FirstFound Then Exit Do
Loop
'Resize rng to include respective data and assign rng to array
Set Rng = Rng.Resize(, 14)
AgentQuestionArray = Rng
d.listQuestion.List = AgentQuestionArray
d.listQuestion.ColumnCount = 14
d.listQuestion.ColumnWidths = ";;;;;;;;;;;;;"
d.MultiPage1.Value = 0
If DataBox.Visible = True Then frmloaded = True
If DataBox.Visible = False Then frmloaded = False
If frmloaded = True Then
ElseIf frmloaded = False Then
DataBox.Show
End If
'Prevents cascading of userform
Application.ScreenUpdating = True
Exit Sub
'Error Handler
NothingFound:
MsgBox "No question data found."
End Sub
Second Module calling AgentQuestionArray:
Rich (BB code):
Private Sub buttDate_Click()
Dim WS As Worksheet
Dim flg As Boolean
Dim Destination As Range
For Each WS In Worksheets
If WS.Name Like "DataTemp" Then flg = True: Exit For
Next
If flg = True Then
WS.Visible = xlSheetVisible
Set Destination = Sheets("DataTemp").Range("A1")
Sheets("DataTemp").UsedRange.ClearContents
Else
Set WS = Sheets.Add: WS.Name = "DataTemp"
Set Destination = Sheets("DataTemp").Range("A1")
End If
If Me.listQuestion.ListCount = 0 Then
MsgBox "You must get data first"
ElseIf Me.listQuestion.ListCount = 1 Then
MsgBox "You need more data then that!"
ElseIf Me.listQuestion.ListCount > 1 Then
Destination.Resize(UBound(AgentQuestionArray, 1), UBound(AgentQuestionArray, 2)).Value = AgentQuestionArray
Call FilterByDate
End If
End Sub
Can anyone explain why this is giving me an error? I'm completely confused because the Destination range works in all my other code, however it is contained within the same module that the arrays are declared as public. Although my understanding is that if its public it should be accessible to all modules or userforms in a project. I could really use help with this and an explanation of how to fix this, since I need to be able to load the array to a worksheet to filter the dates contained in the data.
Last edited: