Wednesday, January 7, 2015

How to import data from one Excel spreadsheet to another using VBA

It can be very helpful knowing how to import data from one Excel spreadsheet to another using VBA. In fact, one of the new features I added to my College Football Bowl Prediction spreadsheet is the ability to import a user’s picks from a separate entry form into the pool manager’s tracking sheet automatically. I did this by inserting a button in the manager’s file that is linked to a VBA macro. If you're brand new to programming macros in Excel, please see my getting started guide here.

How to import data from one Excel spreadsheet to another using VBA

The import spreadsheet VBA code is below. The comments colored green explain what is going on. This code is pretty quick and dirty - no real error handling has been inserted to deal with unexpected situations, something that should be added.

'this code imports a single player's picks into the pool manager
'player's picks must be saved as .xls file
'==============================================================
Sub Import_Single_Player_Data()
' Get player's workbook...
Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook
' make weak assumption that active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook
' get the customer workbook
filter = " *.xls,*.xls"
caption = "Please Select an input file "
customerFilename = Application.GetOpenFilename(filter, , caption)
Set customerWorkbook = Application.Workbooks.Open(customerFilename)
'define the target sheets in order to copy data from customer to target workbook
Dim targetSheet As Worksheet
Set targetSheet = targetWorkbook.Worksheets(2)
Dim sourceSheet As Worksheet
Set sourceSheet = customerWorkbook.Worksheets(1)
'select and copy column L from the new player's spreadsheet
sourceSheet.Columns("L:L").Select
Selection.Copy
'active the pool manager spreadsheet
targetSheet.Activate
'select location where the copied column will be inserted
Columns("L:L").Select
'insert the new column and shift all others to the right
Selection.Insert Shift:=xlToRight
 
' Close customer workbook
customerWorkbook.Close
End Sub

See how this import spreadsheet macro works by downloading the bowl pool manager template. As I’ve stated earlier, using my completed templates is a great way to figure out how to do things that can be applied to other tasks.

By the way, I copied the code into this blog post with formatting by using Notepad++, one of the programming tools I use everyday.

Tuesday, December 30, 2014

Excel Spreadsheets Help Turns Five Years Old

This post is a little bit late, but if you hadn't noticed Excel Spreadsheets Help recently hit another milestone - our 5 Year Blog-iversay! Yes, it's hard to believe but this blog was launched over five years ago, on December 6th, 2009. In fact, check out our very first post here. In those five years we've had several highlights, one of which was reaching over one million pageviews! While the number of total posts has declined every year, I think the quality of the posts has improved (do you agree?). Here's to another five years!


The Top Five Posts from the Last Five Years:


  1. How do I Insert the Degree Symbol
  2. How do you flip or reverse a column
  3. Project Management Downloads
  4. How to make horizontal rows into vertical columns
  5. How to create collapsible rows in Excel


Year in Review 2014 and 2015 Goals

In 2014, I created some new spreadsheet templates and upgraded some old ones. Many readers were asking for more tips though, and I did my best to deliver with posts such as how to make Excel drop down arrows visible, and how to align charts. I created a "how to" Index to track all my Excel tips. In 2015, I want to add even more tips and continue to improve my templates. What would you like to see more of on this blog?

What did you accomplish in 2014? What are your Excel spreadsheet goals for 2015? How can I help you achieve your goals?

Monday, December 29, 2014

Printable 2015 NFL Playoff Bracket

The 2014-2015 NFL Playoffs are set to begin on Saturday, January 3rd a week after the end of the crazy 2014 regular season. Two wildcard games will be played Saturday, January 3 and two games will be played Sunday, January 4. Second round games will be played Saturday and Sunday, January 10 and 11. Third round games will be played Sunday, January 17. The NFL SuperBowl will be played Sunday, February 1st. 

printable 2015 nfl playoffs bracket spreadsheet

I've once again created a printable 2015 NFL playoff bracket with team helmets that you can download for free to use in your office pools. The spreadsheet also includes the complete 2015 NFL playoff schedule including game times, dates, and TV stations. Download the file by clicking the link below (file is hosted on Box.com): 



As a Browns fan, it hards to see the three other teams in our division make it to the playoffs while we miss out again! And we still don't have the answer at quarterback. Sigh... So who are you cheering for?

If you enjoy this spreadsheet, please use the share buttons to send to your family, friends, and coworkers. Also, be sure to check back after the playoffs are over and I’ll be posting my Superbowl squares spreadsheet.

Monday, December 8, 2014

2014 NCAA Bowl Prediction Pool with Playoff Bracket

The NCAA college football bowl season is here again which means it’s time to make your picks and predictions about who you think will win each game. One of the best times of the holiday season (other than giving and receiving gifts) is gathering around the TV and rooting for your alma mater or hometown football team. This year has the added bonus of not just single bowl games but the addition of a four team playoff to determine the national champion.

2014 ncaa bowl prediction pool spreadsheet

Features and upgrades over the previous college football bowl pool manager spreadsheet include:

  • Easy method to make each bowl game worth a different point value
  • Updated leaderboard tab and stats
  • Separate entry sheet to pass out to participants/co-worker
  • Complete NCAA college football bowl schedule with game times and TV station
  • The bowl prediction sheets include the football helmet designs for every team (taken from the 2014 helmet schedule spreadsheet), their win-loss record, and the logo for all bowl games. I added the helmets so those players who aren't big college football fans can pick a winner based on their favorite helmet design!

Fun Fact: Fresno State is the only team with a losing record (6-7) while Florida State has the best record at 13-0.

The beauty of this football bowl manager is you will not have to change or modify any formulas yourself (unless you want to of course). Instructions are included within the Excel file and shows you exactly how to add more players (either manually or by using the button that is linked to a macro).

There are now three ways to add participant’s data:
  1. Manual entry using the drop down lists
  2. Copy and paste from the selection sheet to the bowl manager
  3. Use the import macro to automatically import a player’s data into the pool manager by way of a macro (not yet ready to use, check back soon)

I will explain how it works in a later post. But if you were wondering about the nuts and bolts, my spreadsheet uses the rank without ties formula: =RANK(num, ref) + COUNTIF(range,num)-1. in column A, for bowl games with really long names (i’m looking at you san diego county credit union pionsettia bowl) I use the excel shortcut alt+enter to add text to the next line (shortcut post link)

To download the college bowl pool spreadsheets simply click the link below which will take you to the box.com, where the file is hosted. Next, click on the “Download” link in the upper right hand corner. That’s it!

2014 College Football Bowl Pool Manager.xlsm download
2014 College Football Bowl Prediction Entry Form.xls download

Please let me know if you have any questions, comments, find any bugs, or have any suggestions for improvement.  What team are you rooting for?

Monday, December 1, 2014

How to keep Excel drop down list arrows visible

A useful feature in Excel is the drop down list but currently there is no way for a user opening a spreadsheet to be able to tell what cells contain drop down lists without clicking on them. A simple solution that I've used in the past, such as on my personal finance tracking spreadsheet, is to fill all the cells containing drop down lists with the same color.

If you choose this option, you should make a key or insert a text box with a note that the user will see as soon as the spreadsheet is opened.


Another option that's pretty cool is to make a "fake" arrow that is always visible. This video tutorial from Excel Campus shows you exactly how to do so: 


Bill "Mr Excel" Jelen also has a few hacks to make it appear the drop down arrows are always visible that he shares on his YouTube channel (and his was one of the ones featured in my list of 11 best Excel video tutorial channels):



Sorry that the title of this post is a little deceiving as there really is no "good' way to keep Excel drop down list arrows visible but there are some alternative methods. Which of these "hacks" do you like the best? Or do you have your own solution? Or is it never a problem to you?

Tuesday, November 25, 2014

2014 Holiday Gift Ideas for Excel Users and Computer Geeks

Looking for holiday gift ideas for Excel users? The holiday season is right around the corner and it’s never too soon to start thinking about what presents you're going to get your friends, family, or coworkers. To help you out, I’ve made a list of items I think would be very useful or exciting for not only Excel spreadsheet users but computer nerds and tech geeks like myself. Some of these items I use on a daily basis and others are on my own personal wish list. Enjoy and feel free to suggest items by leaving a comment below!

Microsoft Excel and Other Books


Excel 2013 Bible by John Walkenbach. Excel at Excel with the help of this bestselling spreadsheet guide. This book has everything to help you become a power user of Microsoft Excel. Keep it on a shelve near your desk.


Excel 2013 Power Programming with VBA by John Walkenbach. This book covers all the methods and tools you need to know in order to program with Excel.


What If?: Serious Scientific Answers to Absurd Hypothetical Questions. This book contains hilarious and informative answers to important questions you probably never thought to ask, like: What if everyone on earth aimed a laser pointer at the moon at the same time? What if you could drain all the water from the oceans? What if all the lightning in the world struck the same place? Very fun and interesting read!


Tech, Gadgets, and Toys

Microsoft Surface 2: Hands down the best tablet for Excel and other Microsoft Office products. In fact, it comes with fully functional versions of Excel, Word, Outlook, Powerpoint, and Onenote for free. As far as I know, no other tablet has anything comparable. 32 and 64GB versions are available.


Dash and Dot Wonder Workshop Programmable Robots: If you're into programming things like Excel macros and you want to teach your kids the joys of programming then I've found the perfect gift for you. These cute robots are designed to help introduce children to the wonderful world of programming. Oh, and they're fun for adults too!

Raspberry Pi Computer: The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. It's a capable little PC which can be used for many of the things that your desktop PC does, like spreadsheets, word-processing, and games, as well as plays high-definition video. However, you need ALL of the peripheral equipment such as mouse, keyboard, monitor (HDMI output), ethernet cable, power supply.


Laser Project Keyboard: We live in the future! This virtual keyboard is a 63-key QWERTY holograph that projects at full size onto any flat surface, lessening the tediousness of mobile texting and emailing, and helping curb embarrassing auto correct fails.


Phantom Keystroker V2: Remember my post on Excel pranks and practical jokes? Here's a new one for you: attach this evil prank device to your victim's computer and it makes random mouse movements and types out odd garbage text and phrases.


Laser Pointer: I use one of these nearly everyday at my job for meetings and presentations. You can also use it as a toy to play with your cat.



Quadcopter: Why did this make the list? Because it looks like fun! Wouldn't it be great to play with on Christmas morning?

What gifts are you getting for your fellow Excel user?

Monday, October 6, 2014

7 Resources for Excel Macro Programmers

Here’s a list of seven resources I use almost everyday when programming macros in Microsoft Excel:

1. Built in Help Features

The Microsoft Visual Basic Help Documentation can be accessed by going to Help > Microsoft Visual Basic Help or pressing F1 while inside the Visual Basic Editor. The best part about it is the search feature. I use this all the time!
Another built in feature that can help you solve your problems is the object browser and is a great tool to use when you’re stuck and don’t know what to do next. While in the VBE go to View>Object Browser (or simply hit F2) and use the search bar.
7 resources for excel macro programmers
 

2. Developer tab

You should display the Developer tab or run in developer mode when you want to write macros, run macros that you previously recorded, or create applications to use with Microsoft Office programs.



To show the developer tab: Click the Microsoft Office Button and then click Excel Options, PowerPoint Options, or Word Options. Click Popular, and then select the Show Developer tab in the Ribbon check box.

 
3. Flowchart Process Diagrams
When you’re programming a complicated macro it’s often a good idea to visualize how it’s going to work before you start typing away.  For these large problems I like to create flowcharts to get an overall idea of how the code will flow. It also helps to think about the steps the macro will need to perform, including all the user inputs. I often write out a flowchart, decision tree, or quickly sketch a process map. My favorite tool for this task is Draw.IO because it’s free and it lets you create flowcharts right in your internet browser and you can save your charts directly into Google Drive, DropBox, etc.
Begin sketching flowcharts here: https://www.draw.io/
Another option is to use something simple like Excel, Word, PowerPoint, or Snagit, like this flowchart:
 
4. VB Script Functions
No, I haven’t memorized every single function that can be used in VB. Instead, I prefer to know where that information is and simply look it up really fast. This page contains all the built-in VBScript functions, like Date, Array, IsEmpty, etc.
5. Pre-written Excel marcos
It’s easier to start with code you know works rather than writing everything from scratch. I almost always start a new macro by taking snippets of code from macros I’ve written earlier. If you’re new to programming and don’t have a pool of macros to pull from you can use some of mine. I’m compiling a list of Excel macros that can be downloaded from my website. Especially useful is how to combine workbooks.
6. Notepad++
Sometimes you don’t necessarily need Excel to write your code, just a good notepad tool to help you get the job done. You could use Notepad, Wordpad, or Microsoft word, but instead I recommend and absolutely love Notepad++. I use it all the time for tasks like: looking through other programmer’s code, record macros, compare text files for differences, view/edit files. It’s much better than using plain ole Notepad. It’s also where I compile all my examples and tutorials before copying them to my website or book pages.
Download for free here: http://notepad-plus-plus.org/
 


7. Eng Tips / Stackoverflow / Mr Excel Forum
When I’m completely stumped by a programming problem I turn to forums where I can get potential solutions from over programmers. The forums listed are all simple to setup an account at and you can start posting questions right away. Often times, other programmers have had the exact same question and you can find the solution by searching the forums. So if you’ve gone throw tons of Google search pages and are still pulling your hair out, got to one of these forums and get the answer you need.
What tools do you use when programming Excel macros?