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

makiwara

Board Regular
Joined
Mar 8, 2018
Messages
134
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
 

Some videos you may like

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

makiwara

Board Regular
Joined
Mar 8, 2018
Messages
134
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
 

Watch MrExcel Video

Forum statistics

Threads
1,109,341
Messages
5,528,146
Members
409,802
Latest member
joeino

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top