dreen
Board Regular
- Joined
- Nov 20, 2019
- Messages
- 52
I have two workbooks, one with the Code INSIDE of it Sheet1 (which is the codename of the sheet I want to copy values from) and another workbook defined as "y" in this example. I want to copy over the values of cell "K1-K10" in Sheet1 into cell ("F1-F10") of workbook y (For example, I want F1.Value=K1.Value, F2.Value = K2.Value, etc...). Both workbooks are protected with a password, I am only trying to copy values from Sheet1 (that is why I don't unprotect it), but I want to save, close and protect workbook "y" once all of the values copy and paste into it.
When I hit the Activex Commanbutton inside Sheet1, the code is freezing up my workbook. I have double checked the file paths and the sheet names as well, they are correct.
I have also posted screenshots of the code and both workbooks below:
Here is a Screenshot of the code:
Screenshot of Workbook where the code is written inside (codename Sheet1 = Mytest1)
Screenshot of workbook "y" (Where I want to paste the values)
When I hit the Activex Commanbutton inside Sheet1, the code is freezing up my workbook. I have double checked the file paths and the sheet names as well, they are correct.
I have also posted screenshots of the code and both workbooks below:
VBA Code:
Private Sub Commandbutton1_Click()
Dim y As Workbook
Set y = Workbooks.Open(Filename:="???............\Databases\Test 2.xlsm", Password:="Swarf")
With y
For i=1 to 10
Do While cells(i,11).Value<>""
.Sheets("Mytest2").Unprotect "Swarf"
.Sheets("Mytest2").Cells(i,6).Value = Sheet1.Cells(i,11).Value
Loop
Next i
.Password = "Swarf"
.Save
.Close False
End With
End Sub
Here is a Screenshot of the code:
Screenshot of Workbook where the code is written inside (codename Sheet1 = Mytest1)
Screenshot of workbook "y" (Where I want to paste the values)
Last edited: