[RESOLVED] How to validate existing shape in VBA?
I have to pass a value to a shape in another sheet in excel but i get an error when the shape does not exist. im also passing the shape name to a string that's why there will be a possibility that the said shape would not exist. i have to define the shape and its value. so please can anyone help me how to validate if the said shape is existing or not.
here's my code but i get an error when its false
VB Code:
If Sheet4.Shapes(gCell).ControlFormat.Enabled = True Then
Sheet4.Shapes(gCell).TextFrame.Characters.Text = valCel
Else
Sheet4.Range(gCell).Value = valCel
End If
Re: How to validate existing shape in VBA?
Re: How to validate existing shape in VBA?
you have to run through the shapes collection
VB Code:
Sub shapes()
Dim s As Shape
For Each Shape In Sheet4.shapes 'use whatever sheet reference
If s.Name = gcell Then
MsgBox "shape exists"
Exit For
Next
End Sub
Re: [RESOLVED] How to validate existing shape in VBA?
thanks westconn1 it works although i changed your code for while shape as s to make it run. And RobDog888 sorry for wrong posting, thanks for moving it here!