So currently I have mad a whole bunch of programs to allow the user to generate shapes and groups them to save them in a library containing all the "units". Then in another sheet I have a cell drop down list that uses data validation to pull from a table which contains all the Unit names in one column. A generate button will then clear the work area and paste the unit shape group into the unit. This is my code at the moment shown at the bottom. A picture of the work area is also posted at the bottom. For some reason the first time I use generate unit to clear the work area it works fine but as soon as I try to generate a new one the clear function of this code has the error stated in the title. I am so lost. If somebody could help that would be great! Let me know fi there is anything else you may need to help.
VBA Code:
Sub Generate_Unit()
'
' Generate_Unit Macro
'
'
Dim Unit As Variant
Dim workArea As Variant
Set workArea = Range("E12:P46")
Dim sh As Shape
Dim FoundCell As Range
Dim r As Object
Unit = Range("C3:D3").Value
' Range("E12:P46").Select
For Each sh In ThisWorkbook.Sheets("Sheet1").Shapes
If Not Intersect(Range(sh.TopLeftCell, sh.BottomRightCell), workArea) Is Nothing Then
sh.Select False
End If
Next sh
' If Selection Is Empty Then
' Range("A1").Select
' Else
' Selection.Delete
' Range("A1").Select
' End If
Set r = Selection
If TypeName(r) <> "Range" Then
Selection.Delete
Range("A1").Select
End If
Range("A1").Select
Set FoundCell = Sheets("Units").Range("A:A").Find(Unit, , xlValues, xlWhole, , , True, , False)
If Not FoundCell Is Nothing Then
Sheets("Units").Activate
FoundCell.Select
UnitIndex = ActiveCell.Row - 1
Range("T1").Value = UnitIndex
End If
For Each sh In ActiveSheet.Shapes
If Not Intersect(Range(sh.TopLeftCell, sh.BottomRightCell), Range("F" & UnitIndex * 35 + 1, "Q" & (UnitIndex + 1) * 35)) Is Nothing Then _
sh.Select False
Next sh
Set r = Selection
If TypeName(r) <> "Range" Then
Selection.Copy
Sheets("Sheet1").Activate
workArea.Select
ActiveSheet.Paste
Range("A1").Select
Else
MsgBox ("Did not find unit")
Sheets("Sheet1").Activate
Range("A1").Select
Exit Sub
End If
End Sub