yandy
10-11-2023, 04:25 AM
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?
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?