Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBA ActiveSheet.Shapes. ...

79 views
Skip to first unread message

Christian Engel

unread,
Oct 4, 2006, 3:14:40 PM10/4/06
to
Hallo NG,

habe eine ziemlich grosse Exceltabelle, in der eine Spalte mit "Shapes"
gefüllt ist. Eigentlich sollte je Zelle nur ein Shapes eingefügt worden
sein. Leider musste ich feststellen, dass die übernommene Tabelle
teilweise mehrere Shapes je Zelle hat. Wie kann ich per VBA mir z.B. in
einer extra eingefügten Spalte die entsprechende Anzahl eintragen lassen.

Annahmen:

- Spalte B enthält die Shapes (per Cut&Paste eingeügte Grafiken)
- Spalte C soll die in Spalte B eingeügte Anzahl an Shapes je Zeile
enthalten

Mir schwebt eine Funktion ein Makro vor, die/das folgenden Klartext in
VBA durchführt.

- Selektiere Zelle B2
- Zähle Shapes in B2
- Trage "Zählergebnis in C2 ein

- Fahre mit B3 fort ...

Gruß aus Wolfsburg

Christian Engel

Claus Busch

unread,
Oct 4, 2006, 4:05:28 PM10/4/06
to
Hallo Christian,

probiere es mal so:
Sub GrafikenZählen()
Dim shp As Shape
Dim i As Integer
Dim rngZelle As Range

For Each rngZelle In Range("B2:B100")
For Each shp In ActiveSheet.Shapes
If rngZelle.Address = shp.TopLeftCell.Address Then
i = i + 1
rngZelle.Offset(0, 1).Value = i
End If
Next shp
i = 0
Next rngZelle

End Sub

--
Mit freundlichen Grüssen
Claus Busch

Win XP Prof SP2; Office 2000 SP3
claus_busch(at)t-online.de

Eike Bimczok

unread,
Oct 4, 2006, 4:20:04 PM10/4/06
to
Christian Engel schrieb:
Hallo Christian,

deine Beschreibung passt besser noch auf eine UDF (User Defined Function)
'_________________________________________________________________
Function countShapes(myRange As Range) As Long
'10-2006 E.Bimczok
'http://www.profi-excel.de
Dim myShape As Shape

For Each myShape In ActiveSheet.Shapes
If myShape.TopLeftCell.Address(0, 0) = myRange.Address(0, 0) Then
countShapes = countShapes + 1
End If
Next myShape

End Function
'_________________________________________________________________

Aufruf im Tabellenblatt wie eine normale Funktion
=countShapes(A4)


Viel Erfolg + Gruß
Eike
--
http://www.profi-excel.de

0 new messages