Showing posts with label AI. Show all posts
Showing posts with label AI. Show all posts

Wednesday, September 25, 2024

Generate A Random Number In Google Sheets

I was thinking about trying to transfer one of my most popular spreadsheet templates, Super Bowl Squares, from Excel to Google sheets. However, macros do not work in Google sheets. I was thinking about trying to recreate at least some of them, and the first problem to solve was how to make a random number generator script in Google Sheets.

Here's how you can create a Google Apps Script to generate random numbers between 0 and 9 in cells A1 to A9 without any repeats. 

Steps to Create the Google Apps Script:

  1. Open your Google Sheet.
  2. Click on Extensions in the menu.
  3. Select Apps Script.
  4. Delete any existing code in the script editor, and paste the following code:

function generateRandomNumbers() { // Create an array with numbers 0 to 9 var numbers = Array.from({length: 10}, (_, i) => i); // Shuffle the array for (var i = numbers.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = numbers[i]; numbers[i] = numbers[j]; numbers[j] = temp; } // Get the active spreadsheet and sheet var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // Place the shuffled numbers in cells A1 to A9 for (var k = 0; k < 9; k++) { sheet.getRange(k + 1, 1).setValue(numbers[k]); } }
  1. Save the script by clicking the disk icon or pressing Ctrl + S. You can name it something like RandomNumberGenerator.
  2. Close the Apps Script editor.
  3. Back in your Google Sheet, go to Extensions -> Macros -> Import and then select your generateRandomNumbers function.
RandomNumberGenerator google apps script


How to Run the Random Number Generator Script:

  • To run the script, go to Extensions -> Macros -> generateRandomNumbers.
  • The script will place random numbers between 0 and 9 in cells A1 to A9, with no repeats.

If this is your first time running the script, Google Sheets may ask you for permission to run the script. Approve the permissions to proceed. 

In my templates, I make macros easy to use by running them from a button click. Yes, you can run the script from a button in Google Sheets too! Here’s how you can set it up:

Step 1: Create the Script

  1. Open your Google Sheet.
  2. Click on Extensions in the menu.
  3. Select Apps Script.
  4. Delete any existing code in the script editor, and paste the script provided above.
  5. Save the script by clicking the disk icon or pressing Ctrl + S.

Step 2: Add a Button to Google Sheets

  1. Insert a Drawing (for the Button):

    • Go to your Google Sheet.
    • Click on Insert -> Drawing.
    • Click on the Text Box icon in the Drawing toolbar and draw a text box.
    • Type in a label for your button, such as "Generate Numbers."
    • Format the text and shape as you like.
    • Click Save and Close. The button will now appear on your sheet.
  2. Assign the Script to the Button:

    • Click on the drawing (the button) you just created.
    • Click on the three vertical dots in the top right corner of the button, and select Assign script.
    • In the text box that appears, type the name of your script function, which is generateRandomNumbersInRow.
    • Click OK.

Step 3: Use the Button

  • Now, whenever you click the button, the generateRandomNumbersInRow script will run, and random numbers will be placed in the cells G3 to P3.

This provides a user-friendly way to trigger the script without needing to go through the menu every time. The first problem is solved! Onto the next one...

Monday, April 8, 2024

Excel Sports Bet Tracking Spreadsheet Updated

I've updated the Sports Bet Tracking spreadsheet template with some of the features you've been requesting! The upgrades include:

American or Decimal Odds

Choose between American or Decimal odds by using a drop down list on the first sheet. All bets need to use the same odds type and you shouldn't change it once set. 


What's the difference between American and Decimal odds?

Decimal odds (European odds) represent the potential return of a bet, including the original stake, as a multiple of the stake. The odds are presented as a single number, usually with two decimal places. Example: 2.5

American odds, also known as moneyline odds, are a popular format for expressing the likelihood of a particular outcome in sports betting, especially in the United States. American odds can be positive or negative numbers and indicate how much profit a bettor would make on a $100 wager if the bet is successful. They provide a straightforward way for bettors to understand the potential profit or risk associated with a particular bet. Example: -205, +155

Change to Macro Enabled Worksheet

The format of the bet tracking spreadsheet has been changed from .xlsx to .xlsm as I've added a few simple macros.


Click the "Add New Bet" button to input a new bet. Previously you had to scroll to the bottom of the Bet Tracker sheet to add a new bet and potentially drag down all formulas to track the stats. Now the newest bet will always be at the top and you won't have to manually manipulate any formulas.

If you want to clear all your bets there is a button that will do that but be careful - the action cannot be undone.

I don't think macros will work on MAC/iOS/APPLE devices, so you might have to manually drag down the formulas.

Cash Out and Voided Bets can now be tracked

The ability to Cash Out has also been added as well as void or push bets can now be tracked. If you cash out, enter the value you cashed out for in column K, otherwise leave column K blank. If you want to track void or cancelled bets you can select Void from the drop down then delete your wager amount and leave it blank since you get that money back.

How to Transfer Information From Old Versions

In the Bet Tracker sheet, I think columns A through K should be the same so you can copy and paste those, then drag down the formulas in row 2 for columns M-Y.


Let me know what you think about the improvements to the Sports Bet Tracking Spreadsheet in the comments below! And as always, I valuable your feedback if you have ideas for even more improvements. 

Sunday, January 28, 2024

Super Bowl Squares 2024 - The BEST Excel Templates

It's finally time to play Super Bowl Squares! As the biggest sporting event of the year approaches, hardcore football and casual fans alike gear up for an unforgettable Super Bowl experience. To add an extra layer of excitement to your game day festivities, I'm here to introduce you to the magic of Super Bowl Squares and simplify the process with my specially crafted and powerful Excel template. Whether you're a seasoned veteran or a newcomer to this classic game of chance, my template is designed to make organizing and tracking your Super Bowl Squares pool a breeze. Let's get to it!

I’ve been making Super Bowl Squares templates available for you to download since 2012 and the latest versions are the most versatile yet. There are two templates to choose from, I'll explain the pros and cons of each.

2024 Super Bowl Squares - 54 Ways to Play

Released in 2021, this is the more "classic" and straightforward way to play. When you first open the sheet, it has a nice clean look with only one sheet visible. You select the options for how you want to play, click Generate Squares, and it sets up the sheet exactly for the version you want to play. 

excel file for superbowl squares template


The way it works is all the scoring systems are already built into the sheet. If you go to the Squares or the Manager sheet you will find many hidden rows or columns. The Generate Squares macro simply hides or unhides the data based on the user’s selections.


Download 2024 Super Bowl Squares here


Super Bowl LVIII Squares Unlimited

54 ways to play apparently wasn't enough as I still received numerous requests for customizations and more features. This lead to the creation of a new approach to the template: Super Bowl Squares Unlimited. The main difference in how it works is there are no pre-built scoring systems. Instead, they are built on the fly by macros based on the user's input; therefore there are an infinite number of ways to play.


This sheet offers the most flexibility but might take some getting used to. At first it may be a little difficult to understand how the scoring works, so I recommend you watch this video:


Friday, May 12, 2023

2023 NFL Helmet Schedule Spreadsheet

The 2023 NFL schedule was released yesterday and since I used my Excel skills to automate the creation of this spreadsheet I was able to create the NFL Helmet Schedule in less than a minute! All 32 teams, all 18 weeks of the season (now 17 games plus one bye week), all in one spreadsheet:


A job that used to take hour by moving helmets manually is now so easy to do. Yes, that's why I love the power of macros and automation. I wrote the macro myself but nowadays you could probably just ask ChatGPT to write the macro for you.

On previous versions of the sheet I divided out the two conferences on separate sheets: NFC and AFC. This year, I’ve put all the teams into one sheet. However, there is a new filter option where you can filter by NFC or AFC or even by division: AFC North, AFC South, etc.

Download the 2023 NFL Helmet Schedule Spreadsheet here


Watch the video below to see how the filter works. I also so a tip in Excel how to select multiple objects at once with the mouse. And I walk through the populate helmets macro code as well. Lots of good stuff here!

As you can see, the NFL helmet schedule is printable too. You can save the spreadsheet as a PDF file or print it out and pin it up in your cubicle at work. If you do, please email or tweet me a picture of it hanging up - I'd love to see it!

Please note, an email is required to download it. I do this so you will be automatically updated you if changes or additions are made and will update you when the next year’s schedule is ready. I do not use your email for anything else.

As always, I welcome any comments or suggestions about how to fix or improve the sheet! How can I improve this football spreadsheet into something you’ll use all the time during pro-football season? What future features would you like to see?

Sunday, January 8, 2023

Using OpenAI's ChatGPT to Update My Year in Pixels Excel Template

I've been seeing more and more videos on TikTok about this mysterious new artificial intelligence program called ChatGPT. People are saying it will eventually replace Google search. But what really got my attention was a demonstration of ChatGPT writing VBA macros for Microsoft Excel. Now I knew I had to try it for myself. 

I made a Year in Pixels Excel template to track my daily mood back in 2018 but haven't updated it lately. Since it's the start of a new year, I recently received some new comments and questions about how to use and modify the spreadsheet so I figured now would be a great time to update it and add a few new features. Then I had an idea - why don't I use this opportunity to update my mood tracking Excel template to try out ChatGPT? Let's give it a go!


How to have cell fill color conditional formatting change based on the color of another cell?

The request from a user that got me thinking was "how to easily change the colors in my year in pixels sheet?" An experienced Excel user could probably ascertain the colors are applied by conditional formatting formula rules. However, for users who are not Excel savvy, it's not very obvious and there should be an easier way to change the colors. As far as I know, there is none, or at least no easy way in my current version of Excel, to have the fill color in the conditional formatting reference another cell's color. So instead, I will have a macro update the conditional formatting rules at the click of a button. Let's jump over to ChatGPT.

How does ChatGPT work?

Here's the answer after asking it directly: 

GPT (Generative Pre-trained Transformer) is a type of language model developed by OpenAI that uses a transformer neural network architecture to generate text. GPT is trained on a large dataset of text and uses this training to generate new text that is similar in style and content to the training data.

ChatGPT is a variant of GPT that has been fine-tuned on a specific task, such as having conversations with humans. To fine-tune GPT for this task, ChatGPT is trained on a large dataset of conversation data and learns to predict the next word in a conversation based on the words that came before it.

When you input a message to ChatGPT, it processes the message and uses its knowledge of language and conversation patterns to generate a response. It does this by predicting the next word in the conversation based on the input it has received and the context of the conversation so far. The output of ChatGPT is then a response that is generated based on this prediction.

One thing to keep in mind right off the bat: ChatGPT is not always right. It says it right there on the main page under limitations: may occasionally generate incorrect information; may occasionally produce harmful instructions.
For example, I asked "list the ten tallest roller coasters in the world" which should be fairly easy and instead it produces a list that is incorrect and doesn't even make sense.


Not a great start but let's see how it does creating a macro from scratch.

Creating Custom VBA Macros Automatically with ChatGPT

I wasn't sure how specific I needed to be so I decided to err on the side of caution, plus I thought the more detailed I am the less modification I'll probably need to do later. Now I ask ChatGPT: "create a vba macro to make a new conditional formatting rule where range is C4 to N34, if cell value = 5 then change the fill color to the same color as in cell P12." Then it began typing and my jaw dropped.

I copied and pasted the code into Excel VBA editor and it worked! One thing I forgot is this macro will just add new rules applied to the same range. I need to delete all the existing formatting rules before adding new ones, so I ask ChapGPT:


I added the above code to the earlier response and linked it to a newly added button on my sheet. Now a user can change the fill color of a cell, click the button, and the fill colors update automatically to match.

If you want to see all this play out in real time, watch the video I recorded below:

Thoughts on the Future of ChatGPT

It's awesome that it doesn't just spit out the code, but it also suggests how you might need to modify it AND tells you how to run the macro as well. Even though I've only asked it to make simple macros, I already see how this program could save a lot of time.

I'm not done experimenting but so far ChatGPT seems like a much better option over Recoding macros or Google searches that might take you a few tries to find exactly what you're looking for. Especially when you can get custom code on the fly. On one hand, I feel a little obsolete, but on the other I also don't think ChatGPT will completely be replacing programmers just yet as you can see I still had to understand the code and modify it to fit my exact needs.


Download my Year in Pixels template for free here and try it for yourself. Open the macro editor to view the final codes written by ChatGPT.