RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
If I assign a userform a specific worksheet, how then do I reference that worksheet without specifically referencing the name of the worksheet?
Can't I now reference the data through the property of the form?
Code:
Public Sub CCD_REPORT_Click()
Worksheets("Report365").EnableCalculation = True
Worksheets("Report365").Calculate
'--creates instance of roadmap userform, passes variables to it,
' then shows modeless
'--declare variable frm to be a A222ALRTCCDREPORT userform object
Dim frm As A222ALRTCCDREPORT
'--create a new instance of A222ALRTCCDREPORT
Set frm = New A222ALRTCCDREPORT
'--pass worksheet with headers and data to public property of frm
Set frm.Worksheet = ThisWorkbook.Sheets("Report365")
'--show frm to allow user to interact
frm.Show vbModeless
End Sub
Can't I now reference the data through the property of the form?
Code:
Private Sub InitializeControls()
'--set control properties
'--date picker range (this works but I don't see why I need to reference the name anymore)
Me.DTPicker1.MinDate = Worksheets("Report365").Range("A380")
Me.DTPicker1.MaxDate = Worksheets("Report365").Range("A14")
Me.DTPicker2.MinDate = Worksheets("Report365").Range("A380")
Me.DTPicker2.MaxDate = Worksheets("Report365").Range("A14")
Me.DTPicker2.Value = Worksheets("Report365").Range("A14")
'--date picker range (this doesn't work - invalid use of property)
Me.DTPicker1.MinDate = Me.Worksheet.Range("A380")
Me.DTPicker1.MaxDate = Me.Worksheet.Range("A14")
Me.DTPicker2.MinDate = Me.Worksheet.Range("A380")
Me.DTPicker2.MaxDate = Me.Worksheet.Range("A14")
Me.DTPicker2.Value = Me.Worksheet.Range("A14")