![]() |
| FREE Excel STUFF |
|
Search |
| Excel Help. Popular |
| NEW! Multiple Excel Search & Links |
| Excel Formulas |
| Excel Macros |
| Excel Newsletter |
| PRODUCTS |
| Up to $139.00 FREE! |
|
Categories & Search |
| Excel Templates |
| Excel Add-ins |
| Excel Training |
| More.... |
| OTHER |
| Excel Development |
|
|
NEW! More Books.. |
Add Excel Answers & Search To Your Google Toolbar Details |
Current Special! Complete
Excel Excel Training
Course for Excel 97 - Excel 2003, only $145.00. $59.95 Instant
Buy/Download, 30 Day Money Back Guarantee
& Free Excel Help for LIFE!
Back to: Excel VBA . Got any Excel/VBA Questions? Free Excel Help
Speed up code and stop screen flickering:Sub NoScreenRePainting() Application.ScreenUpdating=False 'Your code here. Application.ScreenUpdating=True End Sub
Sub NoCalculations() Application.Calculation = xlCalculationManual 'Your code here. Application.Calculation = xlCalculationAutomatic End Sub
Sub StopAllEvents() Application.EnableEvents = False 'Your code here. Application.EnableEvents = True End Sub
Sub WithARange()
With Range("A1")
.Value = 100
.Font.Bold = True
.Interior.ColorIndex = 6
.Copy Destination:=Range("B1")
End With
End SubSub EmptyText() Dim strWords As String strWords = "Cats" MsgBox strWords strWords = vbNullString MsgBox strWords End Sub
Sub NoAutoFillOrCopy()
Range("A1:A200").FormulaR1C1 = "=SUM(RC[1]:RC[5])"
End SubSub NoCopyAndPaste()
'Instead of:
Sheet1.Range("A1:A200").Copy
Sheet2.Range("B1").pasteSpecial
Application.CutCopyMode=False'Clear Clipboard
'Use:
'By-passes the Clipboard
Sheet1.Range("A1:A200").Copy Destination:=Sheet2.Range("B1")
'Or, if only values are needed:
Sheet2.Range("B1:B200").Value= Sheet1.Range("A1:A200").Value
'Or, if only formulae are needed:
Sheet2.Range("B1:B200").Formula = Sheet1.Range("A1:A200").Formula
'See also FormulaArray and FormulaR1C1 etc
'Instead of:
Sheet1.Range("A1:A200").Copy
Sheet1.Range("A1:A200").PasteSpecial xlPasteValues
Application.CutCopyMode=False'Clear Clipboard
'Use:
Sheet1.Range("A1:A200") = Sheet1.Range("A1:A200").Value
End SubAlways declare your variables correctly!
To quickly view a variables definition:
Select the variable that you want the definition for.
Go to
View>Definition (Shift+F2)
To return to your previous position:
Go to
View>Last Postition (Ctrl+Shift+F2).
Release memory from Object variables:
Sub ReleaseObjectMemory() 'Could be any variable of the Object type Dim wSheet as Worksheet 'Set Object variable Set wSheet = Sheet1 'Your code here. 'Release memory Set wSheet = Nothing End Sub
Don't get caught in the Loop.
Follow this link
to see why Loops should (and usually can) be avoided.
Avoid If, Else whenever possible
More often than not people would use an If, Else Statement to test whether a condition is TRUE or FALSE. There is
however a slightly faster (and less typing) method. The first example shows the common method, while the second shows
a faster method. Of course in such a small example the difference is not
noticeable.
Sub TrueOrFalseSlower() Dim bYesNo As Boolean Dim i As Integer If i = 5 Then bYesNo = True Else bYesNo = False End If MsgBox bYesNo End Sub
Sub TrueOrFalseFaster() Dim bYesNo As Boolean Dim i As Integer bYesNo = (i = 5) MsgBox bYesNo End Sub
Sub ToggleTrueOrFalseSlower() Dim bYesNo As Boolean If bYesNo = False Then bYesNo = True Else bYesNo = False End If MsgBox bYesNo End Sub
Sub ToggleTrueOrFalseFaster() Dim bYesNo As Boolean bYesNo = Not bYesNo MsgBox bYesNo End Sub
Excel Dashboard Reports & Excel Dashboard Charts 50% Off
Special! Free Choice of Complete Excel Training Course OR Excel Add-ins Collection on all purchases totaling over $64.00. ALL purchases totaling over $150.00 gets you BOTH! Purchases MUST be made via this site. Send payment proof to special@ozgrid.com 31 days after purchase date.
Instant Download and Money Back Guarantee on Most Software
Excel Trader Package Technical Analysis in Excel With $139.00 of FREE software!
Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft