Passing worksheet to a public property of a userform

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
I have a userform which when I click on a label launches another userform. On this second userform I want to pass data from a worksheet through a public property.

I have done this before but it does not work in this example and I haven't the foggiest why not?

*I click on label named ICPSOLIDS and it calls a new instance of A1_ICPSUMMARY
Code:
Private Sub ICPSOLIDS_Click()

Dim frm As A1_ICPSUMMARY

'--create a new instance of charting userform A1_ICPSUMMARY
 Set frm = New A1_ICPSUMMARY
   
 '--pass worksheet with headers and data to public property of frm
 Set frm.Worksheet = ThisWorkbook.Sheets("212-R365")

A1_ICPSUMMARY.Show vbModeless
End Sub

And then the code for the userform contains the setting of the Worksheet property (amongst others). But I get an "Object variable not set" when it tries to pass the 'mwksWorksheet' to a function. I can fix the problem (see comment in code) but I don't see why I have to (I want this userform to accept other worksheets as well).

Code:
Option Explicit
'--userform module variables
Private msAxisTitle As String
Private msDataIdentifier As String
Private mrXValues As Range
Private mrYValues As Range
Private miCount As Integer
Private mwksWorksheet As Worksheet

'--public properties
Public Property Let AxisTitle(sAxisTitle As String)
   msAxisTitle = sAxisTitle
End Property
Public Property Let DataIdentifier(sDataIdentifier As String)
   msDataIdentifier = sDataIdentifier
End Property
Public Property Let Count(iCount As Integer)
    miCount = sCount
End Property

Public Property Set XValues(rXvalues As Range)
   Set mrXValues = rXvalues
End Property
Public Property Set YValues(rYvalues As Range)
   Set mrYValues = rYvalues
End Property
Public Property Set Worksheet(wks As Worksheet)
 Set mwksWorksheet = wks
End Property

'userform activates a calls MakeChartSummary()

[COLOR=#222222][FONT=Verdana]'--privateprocedures
Private Sub MakeChartSummary()
 '--creates a new chart, makes a jpg image and displays the image
 Dim MyChart As Chart
 Dim dblZoomSave As Double
 Dim ImageName As String
 Dim sDataIdentifier As String
 Dim lColNdx As Long
 Dim MaxChartNumber As Double
 Dim MinChartNumber As Double
 Dim Padding As Double
 
 
sDataIdentifier = msDataIdentifier
'Code works if I uncomment here - but why do I need to as mwksWorksheet shouldbe set by the
'public property
'Set mwksWorksheet = ThisWorkbook.Worksheets("212-R365")
 
 
 'Code fails in the sGetChartParameter function as mwksWorksheet is not defined.
 msAxisTitle = sGetChartParameter(wks:=mwksWorksheet, _
   sDataIdentifier:=sDataIdentifier, _
   sParameter:="Axis Title")

[/FONT][/COLOR]


 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Your code as presented works fine for me. Do you have an onerror resume next in the calling code? I suspect the issue lies elsewhere
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top