0

Here i have my hundred line of code please enlighten me about how do i put line code into loop here is my try but i wont work out still trying

 If sp.Name Like "Rounded Rectangle*" Or sp.Name Like "Oval*" Then


        For i = 11 To 100

        x = i - 9

        Sheet2.Shapes.Range(Array("Rounded Rectangle " + i)).TextFrame.Characters.Text = Sheet1.Range("A" + x)

        Next i


    End If

and repeat until X = 110

in this case how can i change it in to correct loop please advice

thank you

2 Answers 2

1

This is a general approach to making a loop to cover a string variable....say we want to loop over Shape("Rectangle 1")....Shape("Rectangle 2")....Shape("Rectangle 3)..... , etc.

Dim str As String, i As Long
For i = 11 To 100
    str = "Rectangle " & CStr(i)
    Sheets2.Shapes(str)................
Next i

and use a similar approach to make "A2"..."A3".........

Sign up to request clarification or add additional context in comments.

1 Comment

Sub Adjust() Dim ws As Worksheet Dim sp As Shape Set ws = Sheet2 For Each sp In ws.Shapes If sp.Name Like "Rounded Rectangle*" Or sp.Name Like "Oval*" Then Dim strs As String Dim str As String, i As Long For i = 11 To 100 str = "Rectangle " & CStr(i) strs = CStr(i - 9) Sheet2.Shapes.Range(str).TextFrame.Characters.Text = Sheet1.Range("A" & strs) Next i End If Next End Sub
0

simple math:

For i = 11 To 100

change to

For i = 11 To 119

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.