Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all you have a for loop with only 3 iterations, and you have a switch case for three!!. why can't you move your common code to a new function and call it thrice?</p> <p>And more over each error has a unique number (incase of VBA errors like Subscript out of range etc, or a description if its a generic number like 1004, and other office errors). You need to check the error number, then decide how to proceed, if to skip the part or work around.</p> <p>Please go through this code..I have moved your comon code to a new function, and in that function we will be resizing the shape. If the shape is missing then we will just return false, and move to next shape.</p> <pre><code>'i am assuming you have defined drnme, nme as strings and d1 as integer 'if not please do so Dim drnme As String, nme As String, d1 As Integer dl = 20 drnme = kt + " 90" nme = "door90" If ResizeShape(drnme, nme, d1) Then d1 = d1 + 160 End If 'Just call 'ResizeShape(drnme, nme, d1) 'd1 = d1 + 160 'If you don't care if the shape exists or not to increase d1 'in that case whether the function returns true or false d1 will be increased drnme = kt + " dec" nme = "door70" 'decorative glazed' If ResizeShape(drnme, nme, d1) Then d1 = d1 + 160 End If drnme = kt + " gl" nme = "door80" 'plain glazed' If ResizeShape(drnme, nme, d1) Then d1 = d1 + 160 End If ActiveSheet.Shapes("Txtdoors").Select Selection.Characters.Text = kt &amp; ": " &amp; kttxt Worksheets("kts close").Protect Password:="UPS" End Sub 'resizes the shape passed in. 'if the shape does not exists then returns false. 'in that case you can skip incrementing d1 by 160 Public Function ResizeShape(drnme As String, nme As String, d1 As Integer) As Integer On Error GoTo ErrorHandler Dim sh As Shape Set sh = Worksheets("kitchen doors").Shapes(drnme) sh.Copy ActiveSheet.Paste Selection.ShapeRange.Name = nme Selection.ShapeRange.Top = 50 Selection.ShapeRange.Left = dl Selection.ShapeRange.Width = 150 Selection.ShapeRange.Height = 220 Exit Function ErrorHandler: 'Err -2147024809 will be raised if the shape does not exists 'then just return false 'for the other errors you can examine the number and go back to next line or the same line 'by using Resume Next or Resume 'not GOTO!! If Err.Number = -2147024809 Or Err.Description = "The item with the specified name wasn't found." Then ResizeShape = False Exit Function End If End Function </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload