How can I make my code add text the the front or left of a textbox on a userform?

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
I have a checkbox on a userform and I would like for it to add text to a text box, without replacing the contents if there already is something in the textbox.

I would like for it to be added to the left most of the textbox, essentially being the first text that is viewed when reading the contents.

I have used an if to make the textbox1.text= abc, but I don't want to replace all the contents when there are already some notes in the textbox.

For example if the textbox had the following in it Customer Wants Blue Pots

The end result would be : abc - Customer Wants Blue Pots
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
I have tried the following but I get an object error:

VBA Code:
Private Sub NeedReview_Change()

    Dim existingNotes As String
    
    Set existingNotes = NotesBox.Value

    If NeedReview.Value = True Then NotesBox.Text = "NEEDS REVIEW - " & existingNotes
    
    

End Sub
 

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
Turns out I had to remove the Set
 
Solution
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,126
Messages
5,768,269
Members
425,460
Latest member
Astros1243

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