Dynamically populating a textbox

richiet

Board Regular
Joined
Apr 24, 2002
Messages
51
Hi

I have two cells. A1 contains the label "Total Sales" and B1 contains the value, e.g. "£123,456".

I want these cells to populate a textbox in the same sheet so that the value is bold and on a new line. Something like...

textbox1lu7.jpg


What formula do I need to attach to the text box for this? Naturally if the Total Sales value changes, I want the text box to automatically update.

Can anyone help?

thanks

Richie
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

lozzablake

Well-known Member
Joined
Dec 15, 2005
Messages
818
OK. I think this will do what you want. You need to put this code in the module associated with the sheet where your shape is. I have assumed the textbox is in the same sheet as the cells containing the data

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target = Range("B1") Then
    
        ActiveSheet.Shapes("Text Box 1").Select   'change for name of your text box
        With Selection
            .Characters.Text = "Total Sales:" & Chr(10) & "£" & Target
            .Characters(Start:=12, Length:=Len(Target) + 3).Font.FontStyle = "Bold"
        
        End With
    
    End If
    Target.Select
End Sub
 

lozzablake

Well-known Member
Joined
Dec 15, 2005
Messages
818
I have amended slightly as I realised you wanted a comma format:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target = Range("B1") Then
    
        ActiveSheet.Shapes("Text Box 1").Select   'change for name of your text box
        With Selection
            .Characters.Text = "Total Sales:" & Chr(10) & "£" & Format(Target, "#,##0")
            .Characters(Start:=12, Length:=Len(Format(Target, "#,##0")) + 3).Font.FontStyle = "Bold"
        
        End With
    
    End If
    Target.Select
End Sub
 

Forum statistics

Threads
1,136,514
Messages
5,676,293
Members
419,619
Latest member
jalme

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
Top