• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Shorter code

haai

New Member
I have this code, but I have a lot of shapes, is there a way to make this code shorter?
Thanks
Code:
Sub haai
With ActiveSheet
    .Shapes(1).DrawingObject.Formula = "=$A$1"
    .Shapes(2).DrawingObject.Formula = "=$A$2"
    .
    .
    .
End With
end sub
 
If all the lines follow this pattern, yes, very easily:
Code:
Sub haai
  For js = 1 To X 'where X is the top number
    ActiveSheet.Shapes(js).DrawingObject.Formula = "=$A$" & js
    Next js
  End Sub

If you've never done loops before (the From...End part), it may look difficult, but you'll find loops are something you'll use routinely if you keep programming.

I always name my loop variables "j" and one other letter; in this case "js" for "Shape". You can use any variable name you like, of course.
 
Back
Top