Multiple Text Box Edit

saltkev

Active Member
Joined
Oct 21, 2010
Messages
324
Office Version
  1. 2013
Platform
  1. Windows
Good Morning

I have a number of Text Boxes All with the same name "Time1". I need to edit each of these boxes using VBA to remove the first character which is a Minus. Your help will be much appreciated.


Regards

Kev
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi there, I'm not sure how all the text boxes can have the same name, but that shouldn't effect anything really. This assumes all the text boxes are on the same sheet, you can edit as necessary.

Code:
Dim shp As Shape
Dim tCount As Integer

For Each shp In ActiveSheet.Shapes
    If shp.Type = msoTextBox Then
        tCount = Len(shp.TextFrame.Characters.Text)
        shp.TextFrame.Characters.Text = Right(shp.TextFrame.Characters.Text, tCount - 1)
    End If
Next
 
Upvote 0
Hi there, I'm not sure how all the text boxes can have the same name, but that shouldn't effect anything really. This assumes all the text boxes are on the same sheet, you can edit as necessary.

Code:
Dim shp As Shape
Dim tCount As Integer

For Each shp In ActiveSheet.Shapes
    If shp.Type = msoTextBox Then
        tCount = Len(shp.TextFrame.Characters.Text)
        shp.TextFrame.Characters.Text = Right(shp.TextFrame.Characters.Text, tCount - 1)
    End If
Next

Hi

Not 100% Sure but it looks as if the code will edit all text boxes on the active sheet, unfortunately there are many more that I don't want to edit. The Ones I do want to edit are named "Time1"
 
Upvote 0
Hi there, I'm not sure how all the text boxes can have the same name, but that shouldn't effect anything really. This assumes all the text boxes are on the same sheet, you can edit as necessary.

Code:
Dim shp As Shape
Dim tCount As Integer

For Each shp In ActiveSheet.Shapes
    If shp.Type = msoTextBox Then
        tCount = Len(shp.TextFrame.Characters.Text)
        shp.TextFrame.Characters.Text = Right(shp.TextFrame.Characters.Text, tCount - 1)
    End If
Next

Hi

Not 100% Sure but it looks as if the code will edit all text boxes on the active sheet, unfortunately there are many more that I don't want to edit. The Ones I do want to edit are named "Time1"

Yes, I assumed all the text boxes on the sheet were "Time1". To do this only for the boxes with that name, use this:

Code:
Dim shp As Shape
Dim tCount As Integer

For Each shp In ActiveSheet.Shapes
    If shp.Type = msoTextBox Then
        If shp.Name = "Time1" Then
            tCount = Len(shp.TextFrame.Characters.Text)
            shp.TextFrame.Characters.Text = Right(shp.TextFrame.Characters.Text, tCount - 1)
        End If
    End If
Next
 
Upvote 0
Yes, I assumed all the text boxes on the sheet were "Time1". To do this only for the boxes with that name, use this:

Code:
Dim shp As Shape
Dim tCount As Integer

For Each shp In ActiveSheet.Shapes
    If shp.Type = msoTextBox Then
        If shp.Name = "Time1" Then
            tCount = Len(shp.TextFrame.Characters.Text)
            shp.TextFrame.Characters.Text = Right(shp.TextFrame.Characters.Text, tCount - 1)
        End If
    End If
Next

Cracking, Great Result.

Many Thanks

Kev
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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