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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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