• 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.

inserting shapes

MBS

Member
Hi all,
I want to insert shapes from just 1 to 5.
Numbers 1 to 5 are inserted in 1st column but only 1st shape is inserted on top on theprevious one, while on the other hand code fails while inserting shapes. please let me know why this happens.

>>> use code - tags <<<
Code:
Dim topRow As Range
Dim Shapenumber As Integer
topRow.Value = "Shapenumber"
topRow.Offset(0, 1).Value = "Shape"


For Shapenumber = 1 To 5
    topRow.Offset(Shapenumber, 0).Value = Shapenumber
    topRow.Offset(Shapenumber, 1).Value = ws.Shapes.AddShape(Shapenumber, _
    topRow.Offset(Shapenumber, 1).Left + 5, topRow.Offset(Shapenumber, 1).Top + 3, 20, 10)
   
Next Shapenumber
 
Last edited by a moderator:
We'll probably have to define the question better before trying to answer it, but first I'm confused by this snippet of program code. You define topRow as a range, and then assign "ShapeNumber" to topRow.Value. But topRow hasn't yet been told what range it points to; how can that work? I mean, if you do this:
Code:
Dim topRow As Range
Set ows = ActiveSheet
Set ocs = ows.Cells
Set topRow = Range(ocs(1, 1), ocs(5, 5))
topRow.Value = "ShapeNumber"
...that'll put the character string "ShapeNumber" into 25 cells from A1 to E5. But it seems to me that trying to put something into topRow.Value before topRow has been assigned an actual range is meaningless. What am I missing?
 
Back
Top