Selecting TextBox Shapes in a particular Row using Macro

dineshtendulkar

Board Regular
Joined
Apr 18, 2011
Messages
53
Guys,

Is it possible to select all shapes (textbox) in a particular row and change the textbox values in it. I am having 3 textbox shapes in each row. I want to select only the shapes of the activerow and then change its values using macro.

Somebody help for this problem.

Thanks in advance.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hello
This will work if your rows are all of the same height:

Code:
Sub ChangeTB()
Dim ob As Shape, str$, rh%, tbr(), i%, j%
i = 0
str = ""
rh = ActiveSheet.Rows(1).Height
For Each ob In ActiveSheet.Shapes
    If InStr(ob.Name, "TextBox") > 0 Then
        ReDim Preserve tbr(i)
        tbr(i) = Int(ob.Top / rh) + 1
        str = str & ob.Name & " => " & tbr(i) & vbLf
        i = i + 1
    End If
Next
MsgBox str, vbInformation, "Lines where TextBoxes are:"
For j = 0 To i - 1
    If ActiveCell.Row = tbr(j) Then _
    ActiveSheet.Shapes("TextBox" & (j + 1)).TextFrame.Characters.Text = CStr(j + 1)
Next
End Sub
 
Last edited:
Upvote 0
But the row height changes depending on the shape present in that particular row. could you send me the code irrespective of the row height.
 
Upvote 0
Try this one:

Code:
Sub ChangeTB()
Dim ob As Shape, str$, tbr(), i%, j%
i = 0
str = ""


For Each ob In ActiveSheet.Shapes
    If InStr(ob.Name, "TextBox") > 0 Then
        ReDim Preserve tbr(i)
        tbr(i) = ob.TopLeftCell.Row
        str = str & ob.Name & " => " & tbr(i) & vbLf
        i = i + 1
    End If
Next
MsgBox str, vbInformation, "Lines where TextBoxes are:"
For j = 0 To i - 1
    If ActiveCell.Row = tbr(j) Then _
    ActiveSheet.Shapes("TextBox" & (j + 1)).TextFrame.Characters.Text = CStr(j + 1)
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,428
Messages
6,119,420
Members
448,895
Latest member
omarahmed1

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