macro works differently in different sheets

judgejustin

Board Regular
Joined
Mar 3, 2014
Messages
139
I have been using the code below for years and it has always worked. It has always been assigned to a button that was on the same worksheet it placed the values in. I have just recently attached this code to a different button in a different worksheet but in the same workbook. I did this to make it a simpler process for the users.
Code:
Sub Stage1Certification_Button_Click()
Dim myFiles, e
myFiles = Application.GetOpenFilename(, , , , True)
If Not IsArray(myFiles) Then Exit Sub
For Each e In myFiles
With Worksheets("Stage 1 Certification")
.Protect "dorcusreview", UserInterFaceOnly:=True, DrawingObjects:=True, Contents:=True, Scenarios:=True
Worksheets("Stage 1 Certification").Shapes.AddPicture (e), False, True, Range("D46:D49").Left, Range("D46:H46").Top, Range("D46:H46").Width, Range("D46:D49").Height
With Worksheets("Stage 1 Certification")
Range("D52").Value = Date
End With
End With
Next
End Sub
If I run the code from the new button it places the picture in the correct sheet but several cells higher than the stated range. It does not place the data at all. I have added a button back into the original sheet and linked the same code to it, so both button run the exact same code, and the button in the original sheet again works perfectly.
What am I missing???
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Maybe
VBA Code:
Sub Stage1Certification_Button_Click()
   Dim myFiles, e
   myFiles = Application.GetOpenFilename(, , , , True)
   If Not IsArray(myFiles) Then Exit Sub
   For Each e In myFiles
      With Worksheets("Stage 1 Certification")
         .Protect "dorcusreview", UserInterFaceOnly:=True, DrawingObjects:=True, Contents:=True, Scenarios:=True
         .Shapes.AddPicture (e), False, True, .Range("D46:D49").Left, .Range("D46:H46").Top, .Range("D46:H46").Width, .Range("D46:D49").Height
         .Range("D52").Value = Date
      End With
   Next
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,262
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top