Option Explicit
Sub test()
Dim MyArray() As String
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim Rng As Range
Dim ShpRng As Range
Dim shp As Shape
Dim Cnt As Long
Set WS1 = Worksheets("Sheet1") [COLOR=seagreen]'Change the sheet name, accordingly.[/COLOR]
Set WS2 = Worksheets("Sheet2") [COLOR=seagreen]'Change the sheet name, accordingly.[/COLOR]
Set Rng = WS1.Range("K1:AA6")
Cnt = 0
For Each shp In WS1.Shapes
Set ShpRng = WS1.Range(shp.TopLeftCell, shp.BottomRightCell)
If Application.Union(Rng, ShpRng).Address = Rng.Address Then
ReDim Preserve MyArray(Cnt)
MyArray(Cnt) = shp.Name
Cnt = Cnt + 1
End If
Next shp
WS1.Shapes.Range(MyArray).Group.Copy
[COLOR=seagreen]'Change the position of the top left cell for the group of shapes, accordingly[/COLOR]
WS2.Range("K1").PasteSpecial
End Sub
Option Explicit
Sub test()
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim Rng As Range
Dim ShpRng As Range
Dim shp As Shape
Dim TopPos As Double
Dim LeftPos As Double
Application.ScreenUpdating = False
Set WS1 = Worksheets("Sheet1")
Set WS2 = Worksheets("Sheet2")
Set Rng = WS1.Range("K1:AA6")
For Each shp In WS1.Shapes
Set ShpRng = WS1.Range(shp.TopLeftCell, shp.BottomRightCell)
If Application.Union(Rng, ShpRng).Address = Rng.Address Then
TopPos = shp.Top
LeftPos = shp.Left
shp.Copy
With WS2
.Activate
.Paste
End With
With Selection
.Left = LeftPos
.Top = TopPos
End With
End If
Next shp
Application.ScreenUpdating = True
End Sub
Option Explicit
Sub test()
Dim MyArray() As String
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim Rng As Range
Dim ShpRng As Range
Dim shp As Shape
Dim Cnt As Long
Dim LeftPos As Double
Dim TopPos As Double
Application.ScreenUpdating = False
Set WS1 = Worksheets("Sheet1")
Set WS2 = Worksheets("Sheet2")
Set Rng = WS1.Range("K1:AA6")
Cnt = 0
For Each shp In WS1.Shapes
Set ShpRng = WS1.Range(shp.TopLeftCell, shp.BottomRightCell)
If Application.Union(Rng, ShpRng).Address = Rng.Address Then
ReDim Preserve MyArray(Cnt)
MyArray(Cnt) = shp.Name
Cnt = Cnt + 1
End If
Next shp
WS1.Shapes.Range(MyArray).Group.Select
With Selection
LeftPos = .Left
TopPos = .Top
.Copy
End With
With WS2
.Activate
.Paste
End With
With Selection
.Left = LeftPos
.Top = TopPos
End With
Application.ScreenUpdating = True
End Sub
Option Explicit
Sub test()
Dim MyArray() [COLOR=red]As Variant[/COLOR]
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim Rng As Range
Dim ShpRng As Range
Dim shp As Shape
Dim Cnt As Long
Dim LeftPos As Double
Dim TopPos As Double
Application.ScreenUpdating = False
Set WS1 = Worksheets("Sheet1")
Set WS2 = Worksheets("Sheet2")
Set Rng = WS1.Range("K1:AA6")
Cnt = 0
For Each shp In WS1.Shapes
Set ShpRng = WS1.Range(shp.TopLeftCell, shp.BottomRightCell)
If Application.Union(Rng, ShpRng).Address = Rng.Address Then
ReDim Preserve MyArray(Cnt)
MyArray(Cnt) = shp.Name
Cnt = Cnt + 1
End If
Next shp
[COLOR=red]WS1.Shapes.Range(MyArray).Select[/COLOR]
[COLOR=red] With Selection.ShapeRange.Group[/COLOR]
[COLOR=red] LeftPos = .Left[/COLOR]
[COLOR=red] TopPos = .Top[/COLOR]
[COLOR=red] .Copy[/COLOR]
[COLOR=red] End With[/COLOR]
[COLOR=red] With WS2[/COLOR]
[COLOR=red] .Activate[/COLOR]
[COLOR=red] .Paste[/COLOR]
[COLOR=red] End With[/COLOR]
[COLOR=red] With Selection.ShapeRange[/COLOR]
[COLOR=red] .Left = LeftPos[/COLOR]
[COLOR=red] .Top = TopPos[/COLOR]
[COLOR=red] End With[/COLOR]
Application.ScreenUpdating = True
End Sub