I have 5 macros which pull 5 images from another sheet and crops and sorts them appropriately. I have assigned all macros to a module which is then assigned to the button click to run all macros at once. The issue I am having is that when I run the macros simultaneously, all images get pulled through correctly but only the first image gets cropped. However, when I run the macros individually, they all work correctly. How can I modify my code so that all images are formatted correctly when I run the macros all at once?
Module code:
Main code:
Module code:
VBA Code:
Sub Button1_Click()
Call comp1 'comp1
Call comp2 'comp2
Call comp3 'comp3
Call comp4 'comp4
Call comp5 'comp5
End Sub
Main code:
VBA Code:
Sub comp1()
Dim wks As Worksheet
Dim shp As Shape
Dim shpNew As Shape
Set wks = Sheets("PRESENTATION")
If LCase(wks.Range("G1").Value) = "1" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 0")
Else
If LCase(wks.Range("G1").Value) = "2" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 1")
Else
If LCase(wks.Range("G1").Value) = "3" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 2")
Else
If LCase(wks.Range("G1").Value) = "4" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 3")
Else
If LCase(wks.Range("G1").Value) = "5" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 4")
Else
If LCase(wks.Range("G1").Value) = "6" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 6")
Else
Set shp = Sheets("RentComparableExpanded").Shapes("")
End If
End If
End If
End If
End If
End If
shp.Copy
wks.Paste wks.Range("G11")
With Selection.ShapeRange.PictureFormat
.CropBottom = 25
.CropRight = 5
End With
'End of Comp 1
End Sub
Sub comp2()
Dim wks As Worksheet
Dim shp As Shape
Dim shpNew As Shape
Set wks = Sheets("PRESENTATION")
If LCase(wks.Range("H1").Value) = "1" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 0")
Else
If LCase(wks.Range("H1").Value) = "2" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 1")
Else
If LCase(wks.Range("H1").Value) = "3" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 2")
Else
If LCase(wks.Range("H1").Value) = "4" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 3")
Else
If LCase(wks.Range("H1").Value) = "5" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 4")
Else
If LCase(wks.Range("H1").Value) = "6" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 6")
Else
Set shp = Sheets("RentComparableExpanded").Shapes("")
End If
End If
End If
End If
End If
End If
shp.Copy
wks.Paste wks.Range("H11")
With Selection.ShapeRange.PictureFormat
.CropBottom = 25
.CropRight = 5
End With
'End of Comp 2
End Sub
Sub comp3()
Dim wks As Worksheet
Dim shp As Shape
Dim shpNew As Shape
Set wks = Sheets("PRESENTATION")
If LCase(wks.Range("I1").Value) = "1" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 0")
Else
If LCase(wks.Range("I1").Value) = "2" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 1")
Else
If LCase(wks.Range("I1").Value) = "3" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 2")
Else
If LCase(wks.Range("I1").Value) = "4" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 3")
Else
If LCase(wks.Range("I1").Value) = "5" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 4")
Else
If LCase(wks.Range("I1").Value) = "6" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 6")
Else
Set shp = Sheets("RentComparableExpanded").Shapes("")
End If
End If
End If
End If
End If
End If
shp.Copy
wks.Paste wks.Range("I11")
With Selection.ShapeRange.PictureFormat
.CropBottom = 25
.CropRight = 5
End With
'End of Comp 3
End Sub
Sub comp4()
Dim wks As Worksheet
Dim shp As Shape
Dim shpNew As Shape
Set wks = Sheets("PRESENTATION")
If LCase(wks.Range("J1").Value) = "1" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 0")
Else
If LCase(wks.Range("J1").Value) = "2" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 1")
Else
If LCase(wks.Range("J1").Value) = "3" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 2")
Else
If LCase(wks.Range("J1").Value) = "4" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 3")
Else
If LCase(wks.Range("J1").Value) = "5" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 4")
Else
If LCase(wks.Range("J1").Value) = "6" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 6")
Else
Set shp = Sheets("RentComparableExpanded").Shapes("")
End If
End If
End If
End If
End If
End If
shp.Copy
wks.Paste wks.Range("J11")
With Selection.ShapeRange.PictureFormat
.CropBottom = 25
.CropRight = 5
End With
'End of Comp 4
End Sub
Sub comp5()
Dim wks As Worksheet
Dim shp As Shape
Dim shpNew As Shape
Set wks = Sheets("PRESENTATION")
If LCase(wks.Range("K1").Value) = "1" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 0")
Else
If LCase(wks.Range("K1").Value) = "2" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 1")
Else
If LCase(wks.Range("K1").Value) = "3" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 2")
Else
If LCase(wks.Range("K1").Value) = "4" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 3")
Else
If LCase(wks.Range("K1").Value) = "5" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 4")
Else
If LCase(wks.Range("K1").Value) = "6" Then
Set shp = Sheets("RentComparableExpanded").Shapes("Picture 6")
Else
Set shp = Sheets("RentComparableExpanded").Shapes("")
End If
End If
End If
End If
End If
End If
shp.Copy
wks.Paste wks.Range("K11")
With Selection.ShapeRange.PictureFormat
.CropBottom = 25
.CropRight = 5
End With
'End of Comp 5
End Sub