How to check if a Text Box doesn't exist? My code below

makiwara

Board Regular
Joined
Mar 8, 2018
Messages
171
Hello everybody! I want to loop through a worksheet which contains inserted TextBoxes.

However, the "name" of TextBoxes don't follow each other in a logical way (not 1,2,3..., 100 and so on) It shows sometimes some skipp: 2-3-4, 6-7-8, 10-11-12 because of the paste)

I try to skipp the textbox if it doesn't exist. For example TextBox 1 doesn't exist, but 2-3 and 4 exist.

Why cant my code skip "Textbox 1"? It accepts it if it would exist.

Thank you very much for your help, it means a lot to me! Have a nice day!




Code:
sub test()
[B]
For i = 1 To 1000 Step 1 [/B]


On Error Resume Next


[B]If[/B] IsNull(ActiveSheet.Shapes("TextBox " & i)) = False Then [B][COLOR=#008000]'Textbox 1 doesn't exist, but code doesn't skips here. Why?[/COLOR][/B]
             k=k+1
            ActiveSheet.Shapes("TextBox " & i).TextFrame.Characters.Text = Worksheets("2").Cells(k, "A").Value
[B]end if[/B]

[B]next


[/B]
end sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I tried several methods, and I have tried 1 of the 2 links before.

I would need a suggestion especially in my case, looping through them using for loop and not for each. Thank you very much
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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