Wednesday, October 18, 2017

How to Increase Macro Speed and Decrease Programming Time

Here are some tips to show you how to increase your macro’s running speed as well as how to save programming time when you’re creating a macro.
First, there are a few options in Excel you can automatically turn on or off to help increase your program’s speed. You may have heard of these before, but for those who haven’t here is a quick recap:

Screen Updating: You can turn screen updating off so that Excel does not update the screen image as your code executes to speed up your macro code. No, you won't be able to see what the macro is doing, but it will run faster. Use this code:

Application.ScreenUpdating = FALSE

Be sure to restore the setting to True at the end of your macro
Excel Calculation: You can actually prevent Excel from recalculating a workbook by using the statement:
Application.Calculation = xlCalculationManual
However, when the calculation mode is xlCalculationManual, Excel doesn't update values in cells, and I’ve also heard this could erase the Clipboard Memory or cause other problems with Excel “losing focus”.  If your macro relies on an updated cell value, you must force a Calculate event, with the .Calculate method, which may be applied to either a specific range (Range("MyRange").Calculate) or to the entire workbook (Calculate).
Display Alerts: Set this property to False to suppress prompts and alert messages while a macro is running; when a message requires a response, Microsoft Excel chooses the default response.
Enable Events: This property can be set to False to prevent the application from raising any of its events. Make sure you turn the events off at the start, and back on at all exit points of the procedure.
Now, we can take these a step farther and put them all in a public subroutine to be called upon as necessary. Here’s how to turn all of the above mentioned items on and off at the start or end of a program:
Public Sub SpeedOn()
With ThisWorkbook.Application
    .ScreenUpdating = False
       .Calculation = xlCalculationManual
    .DisplayAlerts = False
    .EnableEvents = False
End With
End Sub
Public Sub SpeedOff()
With ThisWorkbook.Application
    .ScreenUpdating = True
    .Calculation = xlAutomatic
    .DisplayAlerts = True
    .EnableEvents = True
End With
End Sub
Save these two functions in notepad or somewhere you have quick access to. This way, you do not have to type out this code every time you start a new macro, simply copy and paste the pre-written code.
Another macro speed tip I want to share is, notice how I used the With...End With in the above code? If you are using several statements in a row that apply to the same object, use a WITH statement, rather than fully qualifying the object each time, to help make your VBA macro run faster.
Delete Non-essential Sheets Example
Let’s take it a step further. For example, say you have a macro to delete all sheets in an Excel file except for a few important sheets you’re using that you want to keep. How might you increase the speed of this macro?
Public Sub DeleteAllSheets()
For Each ws In ThisWorkbook.Sheets
    If Not (ws.Name = "Important Sheet 1" Or ws.Name = "Important Sheet 2" Or ws.Name = "Important Sheet 3") Then
        SpeedOn
       ws.Delete
        SpeedOff
    End If
Next ws
End Sub
Notice how I call the SpeedOn and SpeedOff functions we created earlier?

Another tip to increase macro speed: when looping through a collection it is usually faster than the FOR EACH statement rather than using the index.  For example, in the code above I used FOR EACH. It would work but would run slower to use a FOR…NEXT loop:

Dim i as Integer
For i = 1 To Worksheets.Count
        If Not (ws.Item(i).Name = "Important Sheet 1" Or ws.Name = "Important Sheet 2" Or ws.Name = "Important Sheet 3") Then
        SpeedOn
        ws.Item(i).Delete
        SpeedOff
    End If
Next i
I hope these tips help increase the speeds of your macros and decrease your coding time. If you have any other tips you’ve implemented yourself I would love to hear about them!

Saturday, August 19, 2017

2017 NFL Helmet Schedule Spreadsheet

Available to download now is the 2017 NFL helmet schedule spreadsheet. You’ll see a comprehensive breakdown of every NFL pro football team's 2017 season schedule with an image of each team’s helmet design. The NFL helmet schedule is printable too. You can save the spreadsheet as an PDF file or print it out and pin up in your cubicle at work.

 



Email required download link (to automatically update you if changes or additions are made and will update you when the next year’s schedule is ready)



No email required (no notifications):


As always, I welcome any comments or suggestions about how to fix or improve the sheet!
How can I improve this spreadsheet into something you’ll use all the time during pro-football season? Maybe in the future I should also include the option to see different styles of helmets too, like these. Or maybe the Disney-inspired team logos that this guy created. What future features would you like to see?

Tuesday, July 25, 2017

2017 College Football Helmet Schedule Spreadsheet

The 2017 college football season is a little over a month away! I still can’t believe my Buckeyes got shut out in the playoff game against Clemson. I really have no idea what to expect this season.


It’s fun looking at the 2017 college football helmet schedule to try to predict which games you think your favorite team will win or lose. This spreadsheet of the college football schedules includes every team from all conferences plus independents. Every game is listed as either home, away, or neutral site (noted at the bottom of each sheet).  A college football helmet schedule spreadsheet may be available on other websites but, to my knowledge, this is the only downloadable Excel version and, unlike some of the others, is 100% FREE!

college football helmet schedule 2017



I’ve finally done it! I’ve been creating the college football helmet schedule spreadsheet since 2011, and every year I manually update every single helmet. This took forever and unfortunately resulted in many manual entry mistakes: helmets not going with the correct team and so on.


Until now.


With a little help, the creation of this template has finally been automated. The football schedules are pulled directly from ESPN. I've even linked the helmets to the team's website on ESPN. Hopefully this automation will eliminate the manual input errors as well as decreasing creation time. In a future post I hope to show you how the macro works.




I’m happy to say this year’s sheet contains 245 different college football team helmets! It’s surprising how small the file size is when considering how many helmets there are.


Email required download link (to automatically update you if changes or additions are made and will update you when the next year’s schedule is ready)



No email required (no notifications):



As always, I welcome any comments or suggestions about how to fix or improve the sheet!

Here I am running after my son down the ramp at Ohio Stadium!


Tags: 2017 NCAA Excel Helmet Schedule

Saturday, June 10, 2017

How to Hide Gridlines in Excel - Three Ways

Gridlines in Excel are the faint, grey colored lines that appear around cells in a spreadsheet to distinguish them from one another. By default, the gridlines are displayed in worksheets using a color that is set by Excel. You can essentially turn off the gridlines, cover up the gridlines, or change their color in order to hide them.
There are at least three methods you can use to hide the gridlines in Excel.
1. The proper method is to go to View then uncheck the Gridlines box. You can hide gridlines on multiple sheets by selecting all the sheets first, then unchecking the box.



2. Change a cell’s fill color to white or another color. If you apply a fill color to cells on your worksheet, you won't be able to see or print the cell gridlines for those cells.

3. Change the gridline’s color to white. You can change the default Gridline color by going to File > Options > Advanced then scroll down to Display options for this worksheet.

To see how to do each one of these check out the video below.

Borders are not the same as gridlines in Excel

People often confuse borders and gridlines in Excel. Gridlines cannot be customized in the same manner that borders can. If you want to change the width or other attributes of the lines then you need to use a border. Gridlines are always applied to the whole worksheet or workbook, and can't be applied to specific cells or ranges. If you want to apply lines selectively around specific cells or ranges of cells, you should use borders instead of, or in addition to, gridlines.



Let me know if you found this Excel tip helpful!

Sunday, June 4, 2017

Best Excel Spreadsheet Memes - Prepare to Laugh

I've given hundreds of useful Excel tips since I started blogging eight years (!) ago in 2009. But I can't be 100% serious all the time. I've gotta have a little fun from time to time, like when I shared some of the best Excel pranks and practical jokes, not to mention all the sports related templates I produce. And who doesn't love a good joke or meme? So today I thought I'd share the best Excel spreadsheet memes I've collected over the years!

WARNING: Some of these Excel memes might make you literally laugh out loud. You've been warned.

Best Excel Spreadsheet Memes



How'd you know I like Excel? It's not like I write articles or make videos about it...


Yeah, not gonna happen, I'll make my Excel formulas as long as I want to!


Hmmm ok...


I hope not.


Mind = blown.


It's so worth it once you do you learn Excel VBA though.


Gotta have at least one grumpy cat meme.


Ever feel like this?


Me neither. Do people do that? Remove the gird lines by changing the grid lines color to white?



How many have hid non-working formulas before? Admit it if you have!


Haha, not necessarily.




There's always that one co-worker who spends more time formatting then working on the actual information within the Excel sheet.




When writing those super long formulas in Excel....



Drives me crazy.



When can you ever have enough spreadsheets?


I concur Steve!


Which Excel meme is your favorite? Please let me know by commenting below. Or if have a hilarious one that I failed to mention PLEASE send it to me!

Monday, March 13, 2017

2017 March Madness Excel Brackets

It’s the most wonderful time of the year! March Madness 2017 edition is here and the first of the four “play-in” games will begin on Tuesday, March 14th (which we’re not counting off any points for in my office pool). Once again, I’ll be using David Tyler’s NCAA Excel brackets, the same ones I’ve been using since at least 2010, as they're still the best as far as I’m concerned. I'd like to give a special thanks to David for continuing to update and post his excellent brackets each and every March and giving us something to look forward to as we crawl out of the final few weeks of winter (70 degrees a few weeks ago here in Ohio, now it’s snowing!).

I’m a firm believer that a great way to increase your Excel knowledge is to reverse engineer Excel spreadsheet templates, like these office pool March Madness brackets. Previously, I’ve shared 11 things you can learn from the best Excel brackets and they all still apply for this year’s version. David doesn't lock or hide anything behind password protection so you can examine all the formulas to see how they work and make any modifications you desire. There are two files: the bracket manager and the individual bracket file, that can be downloaded by following the link below. Download the files and start picking them apart!

http://www.whistleblows.com/

 If you’re worried you might not be able to use the March Madness Excel brackets have no fear. They are easy to use and you can watch this short video I made to show you just how easy it is to use David's brackets. Simply click on each team to advance them (don't forget to enable macros).

 

 As far as actually filling in the bracket, here are some interesting stats about March Madness and a few tips that might help you choose your teams.
  2017s-March-Madness-By-The-Numbers-v5
Source: WalletHub


  • A No. 16 seed has never beaten a No. 1. Like ever.
  • A No. 12 seed usually beats a No. 5 seed.
  • Odds of picking a perfect bracket: 1 in 9.2 quintrillion.
  • Odds of picking a perfect bracket using historical data and basketball knowledge: 1 in 128 billion.


I know some readers of this blog skip over the templates I post, especially if they're sports related. but there really are many lessons that can be learned by examining them that you can apply to your own spreadsheets to improve them. What new lessons about Excel have you learned by breaking down a template?

Wednesday, March 1, 2017

How to copy a formula down with a macro

Using VBA macros in Excel can make life easier. Here's another example of how. Let’s say I have formulas in row 2 of Sheet2 that I want to copy down a specified number of rows. The number of rows I want to fill the formula down is a value in A1 on Sheet1. Below is the code to show you how to do it along with my comments.

Sub Copy()

'Declare variables. R1 is the range to copy. R2 is the range where we want to put the formulas in the spreadsheet. M is the number of rows to fill to.
Dim r1 As Range, r2 As Range, m As Long
Dim ws1, ws2 As Worksheet
   
'get the row number to copy to from Define Variables sheet
Set ws1 = ThisWorkbook.Sheets("Sheet1")

The number of rows I want to fill the formula down is in A1, plus one for the header
m = ws1.Range("A1") + 1
       
Set ws2 = ThisWorkbook.Sheets("Sheet2")

Declare the range that you want to copy. In my case, the formulas are on Sheet2, in the second row, columns A to Z.
Set r1 = ws2.Range("A2:Z2")

Declare the range you want to fill in. In my example, I want to fill in from A2 through column Z, and down to the row number earlier defined as M.
Set r2 = ws2.Range("A2:Z" & m)
   
Finally, copied the first declared range into the fill declared range.
    r1.Copy r2
   
End Sub

Conversely, if you want to add a command button to your spreadsheet that will automatically clear a range in a sheet, you could use the following VBA code:

Sub Clear()

Dim r1 As Range
Dim ws1, ws2 As Worksheet
Set ws1 = ThisWorkbook.Sheets("Define Variables")
Set ws2 = ThisWorkbook.Sheets("AJ Generator")

Dim m As Integer
m = ws1.Range("L2") + 1
Set r1 = ws2.Range("A3:AJ" & m)

r1.Clear


End Sub