Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
I have worksheet 'temp_ws' publicly defined in a module exclusive to defining public variables to be used with the scope of my entire project.
temp_ws is set in the code of a standard module called "GetUniques", which is called from with some userform initialization code.
Once this module has been processed, the application resumes with the userform initialization code. Upon reaching this line ...
Code within module 'Refine_Schedule' is executed ...
I am receiving an "Object variable or With block variable not set" error with the lines in red. It appears that the value for 'temp_ws' wasn't carried over despite it being publicly defined and set in previous code. One of my biggest challenges is passing shared variables between modules and between userforms and modules. Clearly this is once again the issue.
Will anyone advise where I may have went wrong in my code and/or assumptions?
Rich (BB code):
public temp_ws as worksheet
temp_ws is set in the code of a standard module called "GetUniques", which is called from with some userform initialization code.
Rich (BB code):
Sub GetUniques(ByVal temp_ws As Object)
'analyses data in schedule.csv determining range of dates within database and the number of records unique to those dates
Dim d As Object 'scripting dictionary
Dim c As Variant, i As Long
Dim data_file_list As Name 'named range containing unique dates & record #s for use as listbox rowsource
Application.ScreenUpdating = False
'MsgBox wb_sched.Name
With ws_sched
Set d = CreateObject("Scripting.Dictionary")
'llastrow = .Cells(Rows.Count, 1).End(xlUp).Row
c = .Range("M1:M" & llastrow)
For i = 1 To UBound(c, 1)
d(c(i, 1)) = 1
Next i
End With
Set temp_ws = wb_sched.Worksheets.Add
temp_ws.Name = "temp_ws"
Once this module has been processed, the application resumes with the userform initialization code. Upon reaching this line ...
Rich (BB code):
Refine_Schedule temp_ws
Rich (BB code):
Sub Refine_Schedule(ByVal temp_ws As Object)
Dim c1 As Long, norec As Long
Dim t_fac As String, myVal As Variant, bv1 As String, bv2 As String
Dim red_ref As Long, red_fcn As Long, red_fac As Long, red_class As Long, red_classc As Long
Application.ScreenUpdating = False
With ws_sched
,,, code ,,,
End With
red_ref = Application.WorksheetFunction.CountIf(ws_core.Range("A:A"), "ref") 'count of reference eliminations
red_fcn = Application.WorksheetFunction.CountIf(ws_core.Range("A:A"), "fnc") 'count of function eliminations
red_fac = Application.WorksheetFunction.CountIf(ws_core.Range("A:A"), "fac") 'count of facility eliminations
red_class = Application.WorksheetFunction.CountIf(ws_core.Range("A:A"), "X") 'redundant facilities eliminations
red_classc = Application.WorksheetFunction.CountIf(ws_core.Range("A:A"), "X2") 'no service class C eliminations
Debug.Print temp_ws.Name
With temp_ws
,,, code ,,,
End With
End Sub
I am receiving an "Object variable or With block variable not set" error with the lines in red. It appears that the value for 'temp_ws' wasn't carried over despite it being publicly defined and set in previous code. One of my biggest challenges is passing shared variables between modules and between userforms and modules. Clearly this is once again the issue.
Will anyone advise where I may have went wrong in my code and/or assumptions?