ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Business and Employment»
  • Learn Business Skills

Creating a UserForm in Microsoft Excel - Step 2 - Preparing the Table (A Dynamic Range)

Updated on February 26, 2012

This is the the second Hub of the series: "Creating A Userform in Microsoft Excel". In this series we will walk through the steps of creating a simple address book that will be managed via a userform.

The Table Behind the Scenes

Now that you have accessed the Visual Basic Editor, go ahead and minimize it because we won't use it just yet.

In this Hub, we will create the table that will house our address book.

For this simple address book we will include the following fields:

  • Last Name
  • First Name
  • Address Line 1
  • Address Line 2
  • City
  • State
  • Zip Code
  • Relation
  • Christmas Card (Y/N)

Simply put those fields as column headings on the top row of Sheet1.


Address Book - Table

Name Manger

Creating a Dynamic Range

Creating the table in the sheet is really easy but giving it an official name that excel will recognize is a little trickier. Naming ranges is something that you can do in excel to make writing formulas a little easier. For example: Let's say that you wanted to add "Cost" (located in Cell "A1") and "Tax" (located in cell "A2") together to get "Total Cost". One way to achieve this would be to write a formula like this:

=A1+A2

That would work well, but if your formula were more complex it might be nice to reference the variable by name rather than its cell location. To do this you would create a "Named Range" for each of the variables. You do this using the "Name Manager".

To access the Name Manager, click on the Formulas Tab and then click on Name Manager.

Within the Name Manager you specify a range (a single cell or a group) and give it a name. You can then use those names rather than the cell's locations. The example formula I gave before could then be written:

=Cost+Tax

for our address book, we will need to reference our list of addresses using VBA so we want to give it a name. The only problem is that we don't know exactly how big our list will be. In fact its size may change on a daily basis. To handle this we need to create a "Dynamic Range". We will do this by using the offset function and a nested Counta function. I'll show you the function, then walk you through it.

=OFFSET(Reference, Rows, Cols,[Height],[Width])

=OFFSET(Sheet1!$A$1,1,0,COUNTA(Sheet1!$A:$A),9)

Offset tells excel that we want to give a starting point but ultimately use a located a specified distance away from that starting point.

Reference is that starting point. For our address book we want to start in the upper left-hand corner which is cell A1 on Sheet1. (When writing the formula, just click in cell A1 and it will automatically put in the dollar signs and exclamation point that you need to make it work right.)

Rows is how many rows from the reference you want your range to begin. In our case we want to go down one row, because that is where our first address will be. So we use "1".

Cols is how many columns from the reference you want your range to begin. In our case we want to start on the same column as our reference so we won't move any. "0".

If we were just referencing a single cell, we would be done which is why Height and Width are in brackets (they are optional). However, we want to reference a multi-cell range so we will include the Height and Width.

Height is the number of rows your range includes. Since this number will vary, we will use the Counta function. Counta counts the number of cells in a range that aren't blank. The range I have referenced for Counta is the entire A column. If we have three addresses in our table then counta will give us 4 because it counts the 3 addresses and the 1 column header.

Width is the number of columns your range includes. In our case, our Address Book table (range) has 9 columns.

So now we have a range that will grow and shrink depending on the number or addresses we have.

Go ahead and open the Name Manger and click "New". In the box that appears type in the name that you want to give your range. I chose "Address_Book". I used the underscore (_) because the name of a range can't have any spaces.

In the "Refers to:" box, type our formula. Remember, you can click in the cells that you want to reference and it will input the appropriate text. Once the formula is complete click "OK". When the Name Manager appears again, click on the "Reference" icon to the right of your formula to test it out. It will display the range you have specified.


A Dynamic Range

Join me in my next Hub in this series "Creating a Userform in Microsoft Excel" where we will return to the Visual Basic Editor and lay out the userform that will be used to manage our Address Book.

Comments

    0 of 8192 characters used
    Post Comment

    • Parker Brother profile image
      Author

      Parker Brother 4 years ago

      I'm glad you have found it helpful. I apologize for not getting around to completing the series.

    • profile image

      supert8ch 4 years ago

      Where is the rest of the series? I like it and so far is helpful.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: "https://hubpages.com/privacy-policy#gdpr"

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized. (Privacy Policy)
    CloudflareThis is used to quickly and efficiently deliver files such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisements has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)