Using VBA to insert userfom Textbox value into a textbox within a chart

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
Hi,

I'm trying to populate a textbox (Textbox1) which is embedded within a chart (Chart1). Chart1 is found on the sheet called "Christmas".
I'm wanting to populate textbox1 with the value of a textbox ("TBFrom1") from a userform.

I've been looking everywhere for answers but haven't found anything that works.

I've tied the following bit of code but it throws an error when setting the cht value.

Thanks in advance for any help,

Mike

VBA Code:
Private Sub CBCreate_Click()

Worksheets("Christmas").Activate

Dim cht As Chart
Dim txtB As TextBox

Set cht = Charts("Chart1")
Set txtB = cht.TextBoxes("Textbox1")
txtB.Text = Me.TBFrom1.Value

Unload Me


End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
got it sorted using the following:

VBA Code:
  Dim w As Worksheet
    Dim c As ChartObject
    Dim s As Shape
    Dim sMsg As String
    Dim sName As String


    
       For Each c In ActiveSheet.ChartObjects
            For Each s In c.Chart.Shapes
                If s.Type = msoTextBox And s.Name = "TextBox 3" Then
                    s.TextFrame2.TextRange.Text = Me.TBFrom1.Value
                    
                    Else
                    
                    If s.Type = msoTextBox And s.Name = "TextBox 8" Then
                    s.TextFrame2.TextRange.Text = Me.TBTo1.Value
                    
                    Else
                    
                    If s.Type = msoTextBox And s.Name = "TextBox 9" Then
                    s.TextFrame2.TextRange.Text = Me.TBDate1.Value
                    
                    Else
                    
                    If s.Type = msoTextBox And s.Name = "TextBox 10" Then
                    s.TextFrame2.TextRange.Text = Me.TBSec1.Value

                 End If
                 End If
                 End If
                End If
            Next s
        Next c
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,674
Members
448,977
Latest member
moonlight6

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