Results 1 to 9 of 9

Thread: VBA - define variables for shape names & use in a loop function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Oct 2023
    Posts
    11
    Location

    VBA - define variables for shape names & use in a loop function

    hello i am new to vba.

    Would like to ask how I can define variables for shape names & use in a loop function.

    For example, I have drawn 31 different shapes and I named them SShape1, SShape2, SShape3 until SShape31.

    And I would like to control the shapes to be changed to different colors when they hit a certain conditions.
    I figured out the vba code to change to different colors under different conditions for one shape by the selecting the shape name i defined, and I would like to repeat the same code for the 2nd, 3rd, until the 31st shape, how can I convert the shape name into the loop function?

    My original code to select SShape1 to change to a color:
    ActiveSheet.Shapes.Range(Array("SShape1")).Select
    Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 51, 51)

    I was trying to:

    Dim i As Integer
    For i = 1 to 31
    But I feel like some connections are missing for i with shape name. Do i need to define like below?

    Shapes.Name = "SShape" + i
    And how can I convert SShape i to my code?
    Last edited by Aussiebear; 10-12-2023 at 05:22 AM. Reason: Added code tags to supplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •