Hi,
I was trying to code a macro that transfers specified cell information from one workbook to another by creating a Renew button. The desired functionality of this button is to simply copy & paste the information from the current TEMPLATE to a new TEMPLATE (the two templates are identicle).
The code below is the what I have started with, but I am not sure if this is the right approach.
One problem with this code that I cannot find the answer to is that the merged cells becomes unmerged (for example the cell f4 in the code below are merged with f4:h4 in the current TEMPLATE, however, once the Renew button macro processed, all the merged cells become unmerged and all the spacing in the template gets distorted).
Also, in order for the transformation to occur, the current TEMPLATE and the new TEMPLATE has to be open at the same time. Why is this so and does this has to be done all the time?
Lastly, when clicking the Renew button, the msg box populates as it is indicated in the code below. However, either way if I click 'OK' or 'Cancel' it then populates another msg box that says 'Do you want to replace the contents of the destination cells?' I am not sure where this is being triggered, how there is no difference between 'OK' or 'Cancel'
I hope I was clear enough for good understanding of my situation.
Any suggestions of attacking this problem will be appreciated it.
Thanks,
I was trying to code a macro that transfers specified cell information from one workbook to another by creating a Renew button. The desired functionality of this button is to simply copy & paste the information from the current TEMPLATE to a new TEMPLATE (the two templates are identicle).
The code below is the what I have started with, but I am not sure if this is the right approach.
One problem with this code that I cannot find the answer to is that the merged cells becomes unmerged (for example the cell f4 in the code below are merged with f4:h4 in the current TEMPLATE, however, once the Renew button macro processed, all the merged cells become unmerged and all the spacing in the template gets distorted).
Also, in order for the transformation to occur, the current TEMPLATE and the new TEMPLATE has to be open at the same time. Why is this so and does this has to be done all the time?
Lastly, when clicking the Renew button, the msg box populates as it is indicated in the code below. However, either way if I click 'OK' or 'Cancel' it then populates another msg box that says 'Do you want to replace the contents of the destination cells?' I am not sure where this is being triggered, how there is no difference between 'OK' or 'Cancel'
I hope I was clear enough for good understanding of my situation.
Any suggestions of attacking this problem will be appreciated it.
Thanks,
Code:
Private Sub Renewal2()
On Error Resume Next
Application.ScreenUpdating = False
Dim copyfrom
Dim copyto
copyfrom = ThisWorkbook.Name
copyto = InputBox("Please enter the name of the file you want to copy data to; this file must be already opened. This is case-sensitive and cannot be the same name as the current workbook. Do not add the .xls extension.") & ".xls"
ActiveSheet.Unprotect ("TEMPLATE")
Windows(copyto).Activate
Sheets("TEMPLATE").Activate
Windows(copyfrom).Activate
Range("$F$4").Select
Selection.Copy
Windows(copyto).Activate
Range("$F$4").Select
ActiveSheet.Paste
Windows(copyfrom).Activate
Range("$F$5").Select
Selection.Copy
Windows(copyto).Activate
Range("$F$5").Select
ActiveSheet.Paste
Windows(copyfrom).Activate
Range("$F$6:$G$6").Select
Selection.Copy
Windows(copyto).Activate
Range("$F$6:$G$6").Select
ActiveSheet.Paste
Windows(copyfrom).Activate
Range("$L$4:$M46").Select
Application.CutCopyMode = False
Selection.Copy
Windows(copyto).Activate
Range("$L$4:$M$6").Select
ActiveSheet.Paste
Windows(copyfrom).Activate
Range("E11:L11").Select
Application.CutCopyMode = False
Selection.Copy
Windows(copyto).Activate
Range("E11:L11").Select
ActiveSheet.Paste
Windows(copyfrom).Activate
ActiveSheet.Protect ("TEMPLATE")
Range("F4").Select
Windows(copyfrom).Activate
Range("F4").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = True
.IndentLevel = 0
.ShrinkToFit = True
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.merge
Range("F5").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = True
.IndentLevel = 0
.ShrinkToFit = True
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.merge
Range("F6:G6").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = True
.IndentLevel = 0
.ShrinkToFit = Truse
.ReadingOrder = xlContext
.MergeCells = True
End With
Selection.merge
Range("F4:G4").Select
Sheet1.Protect ("TEMPLATE")
Application.ScreenUpdating = True
End Sub