I have a macro that copies shapes from one sheet to another sheet. What I would like to do is test if the shape has text. If so copy it. If not do not. Below is the code. If there is a cleaner way to do this I am all ears.
Hello, some example code... As not all Shapes have all properties, you have to make them related to their type. Shape.Type 12 is a Textbox.
Checks all shapes on the source sheet and copies them to the destination sheet, it they are textboxes with test in it.
Sub Copy_Shape()Dim shapesCount As LongDim snum As LongDim curShape As ShapeDim curShapeText As StringDim curShapePos As LongcurShapePos = 0shapesCount = Worksheets("Tabelle1").Shapes.CountFor snum = 1 To shapesCount Set curShape = Worksheets("Tabelle1").Shapes(snum) If curShape.Type = 12 Then curShapeText = Worksheets("Tabelle1").OLEObjects(curShape.Name).Object.Value Else curShapeText = "" End If If Len(curShapeText) > 0 Then curShapePos = curShapePos + 1 Worksheets("Tabelle1").Activate Worksheets("Tabelle1").Shapes.Range(Array(curShape.Name)).Select Selection.Copy Worksheets("Tabelle2").Activate Worksheets("Tabelle2").Range("A1").Offset(curShapePos, 0).Select Worksheets("Tabelle2").Paste End IfNextEnd Sub
If you expand the “Full Biography" section of my profile you’ll find links to some articles I’ve written that may interest you.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015, 2017
Experts Exchange Distinguished Expert in Excel 2018
Experts Exchange Top Expert Visual Basic Classic 2012 to 2020
Experts Exchange Top Expert VBA 2018 to 2020
some example code...
As not all Shapes have all properties, you have to make them related to their type.
Shape.Type 12 is a Textbox.
Checks all shapes on the source sheet and copies them to the destination sheet, it they are textboxes with test in it.
Open in new window