• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

how to update chart in userform with checkbox value

delta

Member
my userform have three checkbox and chart while select any checkbox chart is not update
i upload sample file
 

Attachments

  • Book1.xlsm
    27.2 KB · Views: 5
First of all, your formula in B2:D9 range needs to be updated.

In B2:
=IF(H$2= TRUE,Sheet3!B2,"")
Copy across and down.

Then, for each Checkbox, set ControlSource (H2 to J2).

For each Checkbox, at start of Change Event, add "DoEvents" to ensure code fires after update to the sheet is made.

Then Call SavePicture code.

So...
Code:
Private Sub CheckBox1_Change()
    DoEvents
    Call SaveChart
End Sub
Private Sub CheckBox2_Change()
    DoEvents
    Call SaveChart
End Sub
Private Sub CheckBox3_Change()
    DoEvents
    Call SaveChart
End Sub

Private Sub UserForm_Initialize()
    Call SaveChart
End Sub

Sub SaveChart()
    Dim MyChart As Chart
    Dim Fname As String
    Fname = ThisWorkbook.Path & "\temp1.gif"
    Set MyChart = Sheets("Data").ChartObjects(1).Chart
    MyChart.Export Filename:=Fname, FilterName:="GIF"
    Me.Image1.Picture = LoadPicture(Fname)
End Sub

See attached.
 

Attachments

  • Book1 (1).xlsm
    29.2 KB · Views: 5
Back
Top