Hi, I'm new in VBA.
I am trying to insert rectangle shapes x amount of times based on cell input.
Example: cell a1 has 3 entered, make 3 rectangles, if cell a1 has 6 entered, make 6 rectangles.
Can anyone here help me provide the code?
Hi, I'm new in VBA.
I am trying to insert rectangle shapes x amount of times based on cell input.
Example: cell a1 has 3 entered, make 3 rectangles, if cell a1 has 6 entered, make 6 rectangles.
Can anyone here help me provide the code?
Something like this...
Sub J3v16() Dim Ele As Range, Num As Long, i As Long Num = Range("A1").Value For i = 1 To Num Set Ele = Range("B" & i) '! Change B to column you want shape inserted... ActiveSheet.Shapes.AddShape msoShapeRectangle, Ele.Left, Ele.Top, 30, 5 '! Change 30 & 5 to width & height wanted... Next i End Sub
Good Luck
I don't presume to know what I am doing, however, just like you, I too started somewhere...
One-day, One-problem at a time!!!
If you feel I have helped, please click on the star to left of post [Add Reputation]
Also....add a comment if you like!!!!
And remember...Mark Thread as Solved.
Excel Forum Rocks!!!
Pls try this code
Sub CreateRectanglesV() Dim i As Integer Dim rng As Range Dim shp As Shape Dim ws As Worksheet Set ws = ActiveSheet Set rng = ws.Range("A1") For i = 1 To rng Set shp = ws.Shapes.AddShape(msoShapeRectangle, ws.Cells(i + 1, 2).Left, ws.Cells(i + 1, 2).Top, 20, 5) Next i End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks