Okay here are just a few tips which may help.
First, declare all variables and to ensure this happens enable Option Explicit.
Go to the VBE >> Alt + F11 >> Options >> Editor Tab >> Require Variable Declaration.
Second, a little code clean up is necessary. You have a lot in there and it may take some considerable effort, but in the end the your spreadsheet will thank you.
The basic premise; usually there is no need to select an object to work with it in VBA so you can drop most of the Select/Selection, it just slows down the overall speed. As you are recording code, whatever you do is recorded, just like when you scroll the mouse (ActiveWindow.SmallScroll Down:=-6). This part is not necessary and is one of the culprits to slowing overall performance.
Some more reading Beyond the Macro Recorder.
Now, for an example of how you can clean up what you have. If you add a blank sheet to your workbook and title that blank sheet Sheet1 you can run this test code. Open up the VBE and place this code in a module and then place your cursor on the routine. Using F8 you can step through the code and watch it work. This means, if you have a dual monitor setup you can step through the code as you watch it play out on the Excel worksheet.
Here’s a webpage which can add to speeding up code .
Last thing I'll say is indenting code is a very good habit. Not only does it make the code easier for you to follow, but when you ask somebody else to look at your code it will make it easier for them too. One of the links below is for identing code.
Option Explicit
Sub Testing()
With Application
.ScreenUpdating = False
End With
Dim TestingRange As Range
Set TestingRange = Sheets("Sheet1").Range("A1:C10")
With TestingRange
.FormulaR1C1 = "=+0"
.Borders(xlEdgeLeft).LineStyle = xlThick
.Borders(xlEdgeTop).LineStyle = xlThick
.Borders(xlEdgeBottom).LineStyle = xlThick
.Borders(xlEdgeRight).LineStyle = xlThick
.Copy
.Range("F1").PasteSpecial Paste:=xlPasteValues
With Application
.ScreenUpdating = True
.CutCopyMode = False
.Goto [D12]
End With
.Clear
End With
End Sub
Also for the passwords…
With Sheets("Whatever")
.Unprotect "PasswordGoesHere"
'' Your code
.Protect "PasswordGoesHere"
End With
http://www.excelforum.com/2078299-post14.html
http://www.mrexcel.com/forum/showthread.php?t=339643
http://www.mrexcel.com/forum/showthread.php?t=352116
http://www.mrexcel.com/forum/showthread.php?t=517549
Bookmarks