0

I want to make a program that puts a shape at a user defined position. The plan is, that I am typing a cell name (for example "G7" in cell A1) in the cell A1. The value of the cell A1 ("G7") should be taken as the starting point of my shape (Shape starts at G7). Is this possible, because i do no really have a starting point on how to do it. And am i able to delete this shape before i create a new shape via VBA, or do I have to delete it by myself.

So shortly summorized. The value of Cell A1 is "G7". The value should be taken as the starting point for a shape. Reminder, The value of A1 could change.

Thanks for your help

I tried it with InputBox. I tried it as String. But I don't really have the knowledge to complete this code

  • In summary, yes it is possible. However, it is not the point of SO that you ask us to write your code for you. Please have a go at completing your own requirement. If you then have specific problems for which specific answers can be given then come back to the site and ask ... and when you do, post your code (as text). I suggest taking the [SO tour](https://stackoverflow.com/tour) and reading [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – JohnM Jul 31 '23 at 08:18
  • 1
    Hint: Shapes have a `Top` and `Left` property that you *write to*, to set its position. Cells also have a `Top` and `Left` property that you can *read from*. See https://stackoverflow.com/a/16039049/7446760 . – CLR Jul 31 '23 at 08:52

1 Answers1

0

Step one is to get a reference to the cell specified in range A1. Then you can use the top and left properties of that cell to position the shape.

The following code does this and creates a rectangle on the cell specified an A1 of the active sheet:

Sub makeshape()
    Dim cell As Range
    Set cell = Range(Range("a1").Value)
    ActiveSheet.Shapes.AddShape msoShapeRectangle, cell.left, cell.top, 200, 100
End Sub
Gove
  • 1,745
  • 10
  • 11