How to Rank Data Within Groups in Excel: COUNTIFS Method for Analysis

How to Rank Data Within Groups in Excel: COUNTIFS Method for Analysis

Learn­ing how to rank data with­in spe­cif­ic groups is a valu­able Excel skill that can help you orga­nize and ana­lyze infor­ma­tion more effec­tive­ly. By using the COUNTIFS func­tion, you can eas­i­ly deter­mine the rank­ing posi­tion of ele­ments with­in their respec­tive cat­e­gories with­out man­u­al cal­cu­la­tion, sav­ing time and enhanc­ing your data analy­sis capabilities.

This tech­nique is par­tic­u­lar­ly use­ful when work­ing with sales data, per­for­mance met­rics, or any dataset where you need to iden­ti­fy top per­form­ers with­in dif­fer­ent categories.

In my video, I demon­strate how to imple­ment rank­ing with­in groups using a prac­ti­cal example:

Understanding Rank in Groups

When ana­lyz­ing data, we often need to rank items not just over­all but with­in spe­cif­ic cat­e­gories or groups. For exam­ple, you might want to know which sales­per­son per­formed best in each region, or which prod­uct sold most in each store. This is where rank­ing with­in groups becomes essential.

In my demon­stra­tion, I work with a dataset that’s sort­ed by town (our group­ing vari­able) and col­or-cod­ed for eas­i­er visu­al­iza­tion. The data includes dif­fer­ent towns like Moria, Iron­forge, and Azmarin, with each town rep­re­sent­ing a dis­tinct group for our rank­ing purposes.

What makes this tech­nique pow­er­ful is that you can imme­di­ate­ly see how items rank with­in their spe­cif­ic cat­e­gories rather than just see­ing an over­all rank­ing that might be dom­i­nat­ed by one par­tic­u­lar group. This pro­vides much more action­able insights for decision-making.

Using COUNTIFS for Group Ranking

The core of this tech­nique relies on Excel’s COUNT_IFS func­tion, which allows us to count rows where mul­ti­ple cri­te­ria are met simul­ta­ne­ous­ly. This is per­fect for our group rank­ing because we need to check two things at once: whether a row belongs to the same group as our cur­rent row, and whether its val­ue is greater than or equal to our cur­rent row’s value.

The basic for­mu­la struc­ture looks like this:

=COUNTIFS(group_range, current_group, value_range, “>=”&current_value)

Let’s break down how this works in our example:

  • group_range — This is the col­umn con­tain­ing our group­ing vari­able (town names in col­umn A)
  • current_group — This refers to the town in the cur­rent row we’re eval­u­at­ing (A2 for the first data row)
  • value_range — The col­umn con­tain­ing the val­ues we want to rank (rev­enue)
  • current_value — The spe­cif­ic val­ue in the cur­rent row that we’re try­ing to rank

Step-by-Step Implementation

To imple­ment this rank­ing sys­tem in your own spread­sheet, fol­low these steps:

1. First, ensure your data is orga­nized with a clear group­ing vari­able (like town, region, cat­e­go­ry, etc.)

2. Cre­ate a new col­umn for your rank results

3. In this col­umn, enter the COUNTIFS for­mu­la, which will:

  • Check the group col­umn to find rows in the same group as the cur­rent row
  • Check the val­ue col­umn to find val­ues greater than or equal to the cur­rent row’s value
  • Count how many rows meet both cri­te­ria — this count becomes the rank

The for­mu­la uses absolute ref­er­ences (with F4 to cre­ate $ signs) for the ranges and rel­a­tive ref­er­ences for the cur­rent val­ues. This ensures that when you copy the for­mu­la down, it still refers to the cor­rect columns while adapt­ing to each row’s spe­cif­ic values.

Analyzing the Results

After apply­ing the COUNTIFS for­mu­la to our data, we can see that each item gets a rank with­in its group. In our example:

For the town of Moria, we have ranks from 1 to 5

For Iron­forge, ranks range from 1 to 4

For Azmarin, ranks go from 1 to 3

What’s par­tic­u­lar­ly note­wor­thy is that the ranks don’t have to appear in sequence in your spread­sheet. When we sort the entire dataset by rev­enue from largest to small­est, we can see that the high­est-ranked items from each town appear mixed togeth­er. For exam­ple, after the top per­form­ers from Moria, we might see Iron­forge’s top per­former, then more from Moria, then per­haps Azmar­in’s best.

This demon­strates how our rank­ing works inde­pen­dent­ly with­in each group, regard­less of where the items appear in the sort­ed list. The sec­ond-ranked item in Azmarin might appear as the tenth row in our sort­ed data, but it still cor­rect­ly shows as rank 2 with­in its group.

Practical Applications

This rank­ing tech­nique has numer­ous prac­ti­cal applications:

  • Sales analy­sis — Iden­ti­fy top-per­form­ing prod­ucts with­in each category
  • Employ­ee per­for­mance — Rank staff with­in depart­ments or regions
  • Tour­na­ment results — Rank com­peti­tors with­in age groups or divisions
  • Aca­d­e­m­ic per­for­mance — Rank stu­dents with­in class­es or subjects
  • Mar­ket analy­sis — Com­pare per­for­mance of stocks with­in indus­try sectors

By imple­ment­ing this group rank­ing sys­tem, you can quick­ly iden­ti­fy pat­terns that might oth­er­wise be obscured when look­ing at data as a whole. It allows you to make fair com­par­isons with­in rel­e­vant peer groups rather than across dis­sim­i­lar categories.

Additional Tips for Working with Group Rankings

When imple­ment­ing group rank­ings in your spread­sheets, con­sid­er these help­ful tips:

Col­or-cod­ing your data by groups (as shown in my video) makes it much eas­i­er to visu­al­ly iden­ti­fy the dif­fer­ent cat­e­gories and under­stand the rank­ings at a glance.

You can eas­i­ly mod­i­fy the rank­ing log­ic by chang­ing the oper­a­tor in the for­mu­la. For exam­ple, if you want to rank from small­est to largest instead, you would use “<=” instead of “>=” in your COUNTIFS formula.

For ties (when mul­ti­ple items have the same val­ue), this for­mu­la will assign the same rank to all tied items. If you need to han­dle ties dif­fer­ent­ly, you might need to use more com­plex for­mu­las or addi­tion­al columns.

Remem­ber that this tech­nique works with any type of numer­i­cal data you want to rank — sales fig­ures, scores, times, quan­ti­ties, or any oth­er mea­sur­able met­ric — as long as you have a clear group­ing variable.

Excel Pivot Table Hack: Display Percentages of Parent Row Totals

Excel Pivot Table Hack: Display Percentages of Parent Row Totals

Piv­ot tables offer a pow­er­ful way to ana­lyze data, par­tic­u­lar­ly when you need to under­stand pro­por­tions with­in hier­ar­chi­cal cat­e­gories. In this tuto­r­i­al, I’ll show you how to quick­ly add sums in a piv­ot table and dis­play val­ues as a per­cent­age of their par­ent row, allow­ing for imme­di­ate visu­al­iza­tion of how indi­vid­ual items con­tribute to their cat­e­go­ry totals.

This tech­nique is espe­cial­ly valu­able when ana­lyz­ing sales data across prod­uct cat­e­gories and indi­vid­ual items.

Watch my step-by-step video tuto­r­i­al below to see this process in action:

Setting Up Your Pivot Table

To begin cre­at­ing an infor­ma­tive piv­ot table with per­cent­age cal­cu­la­tions, we need to start with a sim­ple dataset that con­tains hier­ar­chi­cal infor­ma­tion. In my exam­ple, I’m using a dataset that includes cat­e­gories (such as fruits, veg­eta­bles, and sweets) along with the spe­cif­ic prod­ucts with­in each cat­e­go­ry and their cor­re­spond­ing rev­enue figures.

The process of cre­at­ing the piv­ot table is straightforward:

  1. Select your data range
  2. Nav­i­gate to the Insert tab in the Excel ribbon
  3. Click on “Piv­ot Table”
  4. Choose to place the piv­ot table on an exist­ing work­sheet (I select­ed cell F1 in my demonstration)
  5. Click “OK” to cre­ate the basic piv­ot table structure

Once your piv­ot table frame­work is estab­lished, you’ll need to struc­ture it prop­er­ly to show both cat­e­gories and their con­stituent prod­ucts. In the Piv­ot­Table Fields pan­el, drag the appro­pri­ate fields to build your hier­ar­chi­cal view.

Structuring Your Pivot Table

For prop­er hier­ar­chi­cal analy­sis, you’ll want to arrange your fields in a log­i­cal order. In the Rows sec­tion of the Piv­ot­Table Fields pan­el, add your Cat­e­go­ry field first, fol­lowed by the Prod­uct field. This cre­ates a nest­ed struc­ture where prod­ucts appear under their respec­tive categories.

For the val­ues sec­tion, we need to add the Rev­enue field twice — once to show the raw sum and once to show the per­cent­age of par­ent. Sim­ply drag the Rev­enue field to the Val­ues area twice. By default, Excel will sum these val­ues, which is exact­ly what we want for this analysis.

Changing the Layout

By default, Excel dis­plays piv­ot tables in com­pact form, but for bet­ter read­abil­i­ty, I pre­fer the tab­u­lar lay­out. To change this:

  1. Go to the Design tab under Piv­ot­Table Tools
  2. Click on “Report Layout”
  3. Select “Show in Tab­u­lar Form”

This adjust­ment sep­a­rates the Cat­e­go­ry and Prod­uct into dis­tinct columns, mak­ing your data more read­able and eas­i­er to ana­lyze at a glance.

Adding Percentage of Parent Row

Now comes the key part — trans­form­ing one of our rev­enue columns to show per­cent­age of par­ent row. This cal­cu­la­tion will show how each prod­uct con­tributes pro­por­tion­al­ly to its cat­e­go­ry total, and how each cat­e­go­ry con­tributes to the grand total. Fol­low these steps:

  1. Right-click on any cell with­in the sec­ond Sum of Rev­enue column
  2. Select “Show Val­ues As” from the con­text menu
  3. Choose “% of Par­ent Row Total”

This sim­ple change trans­forms the raw num­bers into per­cent­ages, giv­ing you imme­di­ate insight into the pro­por­tion­al con­tri­bu­tion of each item. For instance, in my exam­ple, you can now see that apples rep­re­sent approx­i­mate­ly 35% of all fruit sales, while the fruits cat­e­go­ry as a whole rep­re­sents about 41% of total sales across all categories.

Understanding the Results

After apply­ing the per­cent­age of par­ent row cal­cu­la­tion, your piv­ot table auto­mat­i­cal­ly adjusts to show mean­ing­ful pro­por­tions at every level:

  • Indi­vid­ual prod­ucts show their per­cent­age con­tri­bu­tion to their imme­di­ate category
  • Cat­e­go­ry subto­tals show their per­cent­age con­tri­bu­tion to the grand total
  • The grand total always equals 100%

In my demon­stra­tion, this clear­ly showed that sweets account­ed for approx­i­mate­ly 40% of total sales, veg­eta­bles for about 18%, and fruits for approx­i­mate­ly 41%. With­in each cat­e­go­ry, you can sim­i­lar­ly see the pro­por­tion­al con­tri­bu­tion of each product.

Finalizing Your Pivot Table

To make your piv­ot table more under­stand­able, it’s impor­tant to rename the col­umn head­ers to accu­rate­ly reflect what each col­umn rep­re­sents. In our case:

  1. Change the head­ing of the first sum col­umn to sim­ply read “Sum”
  2. Rename the sec­ond col­umn to “Per­cent­age of Parent”

These descrip­tive head­ers ensure that any­one view­ing your piv­ot table will imme­di­ate­ly under­stand what the num­bers rep­re­sent with­out need­ing addi­tion­al explanation.

With these adjust­ments com­plete, you now have a com­pre­hen­sive piv­ot table that not only shows the raw rev­enue fig­ures but also clear­ly illus­trates the pro­por­tion­al rela­tion­ships between cat­e­gories and their con­stituent prod­ucts. This dual-view approach pro­vides both absolute and rel­a­tive per­spec­tives on your data, enabling more nuanced analy­sis and decision-making.

This tech­nique is par­tic­u­lar­ly valu­able when ana­lyz­ing sales per­for­mance, bud­get allo­ca­tions, or any hier­ar­chi­cal data where under­stand­ing pro­por­tion­al rela­tion­ships is impor­tant. By visu­al­iz­ing both raw num­bers and per­cent­ages simul­ta­ne­ous­ly, you gain deep­er insights into your data struc­ture and can more effec­tive­ly com­mu­ni­cate those insights to others.

How to Calculate Hierarchy Levels in Power Query

How to Calculate Hierarchy Levels in Power Query

In this tuto­r­i­al, I demon­strate a prac­ti­cal appli­ca­tion of recur­sive func­tions in Pow­er Query to cal­cu­late hier­ar­chy lev­els in orga­ni­za­tion­al struc­tures or MLM sys­tems. Using a cus­tom func­tion with recur­sion, we can effi­cient­ly deter­mine each per­son­’s posi­tion in a hier­ar­chi­cal struc­ture based on their refer­rer rela­tion­ships, pro­vid­ing valu­able insights for orga­ni­za­tion­al analy­sis and reporting.

Under­stand­ing hier­ar­chy lev­els is essen­tial for visu­al­iz­ing report­ing struc­tures, track­ing MLM down­lines, or map­ping any par­ent-child rela­tion­ships in your data.

Understanding the Problem: Hierarchy Levels in Organizations

In many orga­ni­za­tion­al struc­tures, par­tic­u­lar­ly in mul­ti-lev­el mar­ket­ing (MLM) sys­tems or cor­po­rate hier­ar­chies, under­stand­ing the lev­el depth of each mem­ber is cru­cial. The lev­el rep­re­sents how many steps a per­son is from the top of the orga­ni­za­tion. For instance, in our exam­ple, John is at the top (lev­el 0), N is direct­ly below John (lev­el 1), and Thomas is below N (lev­el 2).

Our sam­ple data con­tains an ID col­umn that unique­ly iden­ti­fies each per­son and a Refer­rer col­umn that indi­cates who brought that per­son into the orga­ni­za­tion. The refer­ral rela­tion­ship estab­lish­es the hier­ar­chi­cal struc­ture we need to ana­lyze. Our goal is to cal­cu­late each per­son­’s hier­ar­chy lev­el auto­mat­i­cal­ly using Pow­er Query’s recur­sive capabilities.

Setting Up Power Query

To begin work­ing with our data, we need to import it into Pow­er Query where we can cre­ate and apply our recur­sive function:

  1. Select any cell in your data table
  2. Go to the Data tab
  3. Click From Table/Range to import your data into Pow­er Query

This imports your data con­tain­ing the ID and Refer­rer columns into the Pow­er Query Edi­tor, where we can start build­ing our solution.

Creating a Recursive Function to Calculate Hierarchy Levels

The core of our solu­tion is a cus­tom func­tion that can call itself (recur­sion) to track up through the hier­ar­chy until it reach­es the top. Here’s how to cre­ate it:

  1. In the Pow­er Query Edi­tor, go to the Home tab
  2. Click New Source > Oth­er Sources > Blank Query

Now we need to define our func­tion. Our func­tion will require two para­me­ters: the per­son­’s ID we want to cal­cu­late the lev­el for and the com­plete table of peo­ple data to ref­er­ence. The func­tion will:

  1. Find the row for the cur­rent person
  2. Get their refer­rer’s ID
  3. Check if they have a referrer
  4. If they don’t (they’re at the top), return 0
  5. If they do have a refer­rer, call the same func­tion for the refer­rer and add 1 to the result

The M code for our func­tion looks like this:

(per­son­ID, personTable) =>
let
per­son­Row = Table.SelectRows(personTable, each [ID] = personID){0},
per­son­AboveID = personRow[Referrer],
result = if per­son­AboveID = null
then 0
else @HierarchyLevel(personAboveID, per­son­Table) + 1
in
result

Make sure to name your func­tion Hier­ar­chyLev­el so that the recur­sive ref­er­ence to itself works prop­er­ly. The @ sym­bol in front of the func­tion name empha­sizes that we’re call­ing the same func­tion again.

Applying the Function to Our Data

After cre­at­ing our func­tion, we need to apply it to every row in our data table:

  1. Go back to your main query with the import­ed data
  2. Click Add Col­umn > Invoke Cus­tom Function
  3. Select your Hier­ar­chyLev­el function
  4. For per­son­ID, select the ID column
  5. For per­son­Table, we need to ref­er­ence the cur­rent table

When set­ting the per­son­Table para­me­ter, we ini­tial­ly might try to ref­er­ence a col­umn name, but this will gen­er­ate errors. Instead, we need to ref­er­ence the entire table from the pre­vi­ous step. In Pow­er Query, we can do this by refer­ring to the pre­vi­ous step name.

Once cor­rect­ly con­fig­ured, the func­tion will cal­cu­late the hier­ar­chy lev­el for each per­son in our table. Thomas, who is referred by N (ID 2) who in turn is referred by John (ID 1), will show as lev­el 2. John, who has no refer­rer, will be at lev­el 0.

Testing and Validating the Recursion

To ver­i­fy our func­tion works cor­rect­ly, we can exam­ine the cal­cu­lat­ed lev­els for each per­son in our organization:

  • John (ID 1): Lev­el 0 (top of hier­ar­chy, no referrer)
  • Anne (ID 2): Lev­el 1 (referred by John)
  • Thomas (ID 5): Lev­el 2 (referred by Anne)
  • Paul: Lev­el 3 (referred by Thomas)

We can fur­ther test by chang­ing refer­rer rela­tion­ships. For exam­ple, if we change Paul’s refer­rer from Thomas (ID 5) to some­one who is already at lev­el 3, Paul would then become lev­el 4. After mak­ing such changes in the source data, we can sim­ply refresh our Pow­er Query to see the updat­ed hier­ar­chy levels.

Handling Edge Cases in Your Hierarchy

Our recur­sive func­tion han­dles sev­er­al impor­tant edge cases:

  1. Top-lev­el mem­bers (those with null refer­rers) are assigned lev­el 0
  2. The func­tion will work for orga­ni­za­tions of any depth, con­tin­u­ing to recurse up the chain until it reach­es the top
  3. If the data con­tains cir­cu­lar ref­er­ences (Per­son A refers to Per­son B who refers back to Per­son A), the recur­sion could cre­ate an infi­nite loop — con­sid­er adding error han­dling for this sce­nario in real applications

In a real-world sce­nario, you might want to enhance this func­tion to han­dle more com­plex require­ments, such as detect­ing cir­cu­lar ref­er­ences or pro­cess­ing mul­ti­ple hier­ar­chies with­in the same dataset.

Loading the Results Back to Excel

Once you’re sat­is­fied with your hier­ar­chy lev­el calculations:

  1. In the Pow­er Query Edi­tor, go to Home > Close & Load
  2. Your data table with the new hier­ar­chy lev­el col­umn will appear in Excel
  3. Any time your hier­ar­chy changes, sim­ply refresh the query to recal­cu­late all levels

This pow­er­ful tech­nique allows you to main­tain an up-to-date view of your orga­ni­za­tion­al struc­ture with min­i­mal effort. The recur­sive approach effi­cient­ly han­dles even large hier­ar­chies with­out requir­ing com­plex for­mu­las or man­u­al tracking.

With this solu­tion in place, you can eas­i­ly build reports and visu­al­iza­tions that lever­age hier­ar­chy lev­el infor­ma­tion, enabling bet­ter insights into your orga­ni­za­tion­al struc­ture, MLM down­lines, or any hier­ar­chi­cal data you’re work­ing with.

Excel Trick: Create Custom Day Sequences With WORKDAY.INTL Function

Excel Trick: Create Custom Day Sequences With WORKDAY.INTL Function

Cre­at­ing a cus­tom sequence of days in Excel can stream­line sched­ul­ing for spe­cif­ic busi­ness needs or project time­lines. By using the WORKDAY.INTL func­tion, you can gen­er­ate sequences that include only cer­tain week­days, allow­ing you to build sched­ules that skip spe­cif­ic days like Fri­days or only include par­tic­u­lar days like Mon­days, Wednes­days, and Fridays.

This tech­nique is espe­cial­ly valu­able for plan­ning recur­ring meet­ings, shift sched­ules, or deliv­ery dates that fol­low non-stan­dard patterns.

In my video, I demon­strate how to cre­ate these cus­tom day sequences in Excel:

Standard Weekday Sequences in Excel

Excel pro­vides a sim­ple built-in method for cre­at­ing stan­dard week­day sequences (Mon­day through Fri­day). When you need a list of dates that excludes week­ends, you can use Excel’s fill han­dle with the “Fill Week­days” option. This approach is straightforward:

  1. Enter your start­ing date in a cell
  2. Hold the right mouse but­ton and drag down as far as needed
  3. Release and select “Fill Week­days” from the con­text menu

This cre­ates a sequence that auto­mat­i­cal­ly skips Sat­ur­days and Sun­days, giv­ing you only the stan­dard work­ing days. How­ev­er, this default method is lim­it­ed to the stan­dard Mon­day-Fri­day work week and does­n’t allow for customization.

Using WORKDAY.INTL for Custom Day Sequences

For more flex­i­bil­i­ty in day selec­tion, Excel’s WORKDAY.INTL func­tion becomes invalu­able. This pow­er­ful func­tion allows you to define which days of the week should be con­sid­ered week­ends (non-work­ing days), effec­tive­ly let­ting you cre­ate sequences with only your desired days.

The basic syn­tax of the WORKDAY.INTL func­tion is:

WORKDAY.INTL(start_date, days, [weekend], [holidays])

Where:

  • start_date: The ini­tial date from which to begin counting
  • days: The num­ber of work­ing days to add to the start date
  • week­end: A para­me­ter that defines which days are con­sid­ered weekends
  • hol­i­days: An option­al para­me­ter for spe­cif­ic hol­i­day dates to exclude

Weekend Parameter Options

The week­end para­me­ter is what gives this func­tion its flex­i­bil­i­ty. Excel offers mul­ti­ple ways to spec­i­fy which days should be treat­ed as non-work­ing days:

  1. Using pre­de­fined week­end codes (1–7 for dif­fer­ent stan­dard week­end patterns)
  2. Spec­i­fy­ing a sin­gle day of the week as a weekend
  3. Cre­at­ing a cus­tom 7‑character text string of 1s and 0s

The third option is the most ver­sa­tile and the focus of my demon­stra­tion. The 7‑character string rep­re­sents the days of the week start­ing with Mon­day (posi­tion 1) through Sun­day (posi­tion 7). Using “0” marks a work­ing day, while “1” marks a week­end/non-work­ing day.

Creating Custom Day Sequences

To cre­ate a sequence that excludes spe­cif­ic days, we can lever­age the text string week­end para­me­ter. For exam­ple, if we want to exclude Fri­days, Sat­ur­days, and Sun­days from our sequence, we would use:

=WORKDAY.INTL(start_date, 1, "0000111")

In this string, the “1“s in posi­tions 5, 6, and 7 rep­re­sent Fri­day, Sat­ur­day, and Sun­day as non-work­ing days, while the “0“s in posi­tions 1–4 indi­cate Mon­day through Thurs­day as work­ing days. By set­ting the days para­me­ter to 1, each appli­ca­tion of the func­tion adds exact­ly one work­ing day to the sequence.

When this for­mu­la is dragged down, it cre­ates a sequence of dates that includes only Mon­day through Thurs­day, skip­ping over the days we’ve des­ig­nat­ed as “week­ends.”

Example: Monday-Wednesday-Friday Sequence

If we want to cre­ate a sequence that includes only Mon­days, Wednes­days, and Fri­days, we would define all oth­er days as non-work­ing days:

=WORKDAY.INTL(start_date, 1, "0101011")

This pat­tern sets Tues­day, Thurs­day, Sat­ur­day, and Sun­day as non-work­ing days (rep­re­sent­ed by “1“s in posi­tions 2, 4, 6, and 7), while Mon­day, Wednes­day, and Fri­day remain as work­ing days (with “0“s in posi­tions 1, 3, and 5). When applied and dragged down, this for­mu­la cre­ates a sequence that cycles through only the three days we want: Mon­day, Wednes­day, Fri­day, Mon­day, Wednes­day, Fri­day, and so on.

Practical Applications

This tech­nique has numer­ous prac­ti­cal appli­ca­tions in busi­ness and per­son­al planning:

  • Meet­ing sched­ules for recur­ring team meet­ings on spe­cif­ic days
  • Class or train­ing sched­ules that occur on select days of the week
  • Shift work pat­terns for employ­ees with cus­tom work­ing days
  • Deliv­ery sched­ules for ser­vices that oper­ate only on cer­tain days
  • Pay­ment or billing cycles that fol­low spe­cif­ic day patterns

By mas­ter­ing the WORKDAY.INTL func­tion with cus­tom week­end para­me­ters, you can cre­ate high­ly spe­cial­ized date sequences that match exact­ly the pat­tern you need, with­out hav­ing to man­u­al­ly select or fil­ter dates.

Additional Considerations

While the exam­ples in my demon­stra­tion focus on the week­end para­me­ter, remem­ber that the WORKDAY.INTL func­tion also accepts a hol­i­days para­me­ter which can fur­ther refine your date sequences by exclud­ing spe­cif­ic hol­i­day dates.

For more com­plex sched­ul­ing needs, you might com­bine this func­tion with oth­er Excel fea­tures like con­di­tion­al for­mat­ting to high­light cer­tain dates or cus­tom num­ber for­mat­ting to dis­play the dates in your pre­ferred format.

The beau­ty of using func­tions like WORKDAY.INTL is that your sequences will auto­mat­i­cal­ly adjust if you change the start­ing date, mak­ing this a dynam­ic solu­tion for sched­ul­ing that can be eas­i­ly updat­ed as needed.

Excel VBA —  How Absolute and relative references in macro work | Introduction to macros and VBA 05

Excel VBA — How Absolute and rel­a­tive ref­er­ences in macros | Intro­duc­tion to macros and VBA 05

Today, we will talk about absolute and rel­a­tive ref­er­ences in macros as well as dif­fer­ent ways to run our macro. 

Today, we are going to record a macro, where we will put the TODAY func­tion. How­ev­er this time, we will press ENTER instead of the Ctrl + Enter short­cut. We can start with cell A5. Let’s use the Record but­ton locat­ed in the sta­tus bar tab this time instead of using the Devel­op­er tab (Fig. 1)

Fig. 1 Record button
Fig. 1 Record button

Let’s call our macro ‘Today2’. We don­t’t need any short­cut but let’s try to add a short­cut here by click­ing the Ctrl + D com­bi­na­tion and see what hap­pens lat­er on. We want to save our macro in the Per­son­al Macro Work­book. When we press OK, Excel won’t allow us to save our macro, because we already have a macro with this short­cut. Let’s delete the short­cut then. When we use a short­cut that already exists in Excel, macro short­cut for macro will be more impor­tant than the default short­cut, e.g. Ctrl key. Thus, we should­n’t use such kind of short­cuts. Let’s press OK (Fig. 2)

Fig. 2 Record Macro window
Fig. 2 Record Macro window

Now, we just write TODAY in cell A5. It’s impor­tant that the Use Rel­a­tive Ref­er­ences isn’t high­light­ed (Fig. 3)

Fig. 3 Use Relative References not highlighted
Fig. 3 Use Rel­a­tive Ref­er­ences not highlighted

After we fin­ished writ­ing TODAY, let’s press ENTER. After writ­ing the for­mu­la, we can see that Excel went down one cell by default. Now, we just press STOP on the sta­tus bar (Fig. 4)

Fig. 4 Stop on the status bar
Fig. 4 Stop on the sta­tus bar

After we stopped our macro, how can we run it now? We can go to the Devel­op­er tab and press the View Macros com­mand or just click the Alt + F8 key short­cut (Fig. 5)

Fig. 5 View Macros command
Fig. 5 View Macros command

In the win­dow that has appeared, we can see all avail­able macros, which are in All Open Work­books. Now, we have only two. We can see that before the macro name, we have the file name. We can choose macros from many files (Fig. 6)

Fig. 6 File name and files

For us, it’s impor­tant to run the Today2 macro, so let’s select it and press the Run but­ton (Fig. 7)

Fig. 7 Run button
Fig. 7 Run button

Excel has writ­ten the TODAY func­tion in our select­ed cell, which is C5 and has gone to cell A6 (Fig. 8)

Fig. 8 Excel in cell A6
Fig. 8 Excel in cell A6

Let’s try a sim­i­lar thing with the firs macro. Let’s press Alt + F8 short­cut, select the Today2 macro and press RUN. Now, let’s see what exact­ly our macro has done. Let’s press Alt + F11. We should see our first macro and our new macro Today2, as well as some com­ments (Fig. 9)

Fig. 9 Our macros
Fig. 9 Our macros

Let’s delete the com­ments as we don’t need them and let’s locate the lines so that they are clear­er to read. Now, we have two lines of the code. The first line of the Today2 macro is very sim­i­lar to the Today macro. How­ev­er, instead of ‘Selec­tion’, we have ‘Active­Cell’. It means that our for­mu­la is writ­ten in the active cell. After the line that con­tains our macro, Excel will always go to cell A6, We can see it in the next line of ‘Range (“A6”). Select. ‘Select’ means the action, i.e. that we have select­ed the cell (Fig. 10)

Fig. 10 Code lines
Fig. 10 Code lines

This is how macros are work­ing. If we select a range, the TODAY func­tion will be placed only in the active cell. Then, Excel will go to cell A6.

Let’s try a sim­i­lar macro. The only dif­fer­ence is that this time we will be using rel­a­tive ref­er­ences. So let’s do it once again: click on the Record Macro but­ton (1), let’s call it Today3 (2), This Work­book (3) and press OK (4) (Fig. 11)

Fig. 11 Recording a new macro
Fig. 11 Record­ing a new macro

We’re writ­ing every­thing once again: TODAY func­tion in cell A7 (1), then Enter (2), then the Stop Record­ing but­ton (3) (Fig. 12)

Fig. 12 The process of recording
Fig. 12 The process of recording

This time we were using rel­a­tive ref­er­ences. Let’s press Alt + F11. Where is our macro? It’s not in the PERSONAL.XLSB file but in our Macro file, where we record. It means that we have to find Mod­ules (1), where Mod­ule 1 should be added (2). Let’s dou­ble-click it and we can see our macros (Fig. 13)

Fig. Module 1 with our new macro
Fig. Mod­ule 1 with our new macro

We don’t need com­ments so let’s delete them again. Let’s also adjust the size of the win­dows so that we can see it clear. We have the TODAY 2 and TODAY 3 func­tions here. We’ve found our macro (Fig. 14)

Fig. 14 Both macros
Fig. 14 Both macros

There is one more way to find our macros. Let’t go to the Devel­op­er (1) tab and go to the View Macros but­ton (2). In the win­dow that appeared we can see that we have many options there like Run, Step into, Edit, Delete and Options (3). For our macro, the Options but­ton is the most sig­nif­i­cant one, because here we can see short­cuts for our macro (4) (Fig. 15)

Fig. 15 Macro options
Fig. 15 Macro options

If we delete D, this macro will delete the short­cut if I press OK. How­ev­er, we’re not going to do that. Let’s close the Macro Options win­dow and let’s focus on the Today3 macro. Since this file is still open, we don’t see any names before. Let’s go to the Edit option of this macro (Fig. 16)

Fig. 16 Edit option
Fig. 16 Edit option

This option leads us to the exact win­dow our macro is stored. The first line in the Today3 macro is exact­ly the same as in Today2 macro. How­ev­er, the sec­ond line is total­ly dif­fer­ent. First of all, both lines start with ‘Active­Cell’. Then, we have Off­set (1, 0) — by one row and 0 columns. It means that we went one cell down. Then, VBA tells us that we select­ed Range A1. In fact, we did­n’t select A1 or any oth­er cells. Some­times, it’s hard to under­stand VBA due to some inputs. It’s true that we did­n’t select A1, but when we went one cell down from the active cell, we select­ed a range that is the same size as range A1 cell. 

Once again. First we start with Active Cell, then there is a dot, which means that we take anoth­er step, then choos­ing the Off­set, one row, 0 columns, then we have the Range A1 and what we do with this range, which is select­ing the range (Fig. 17)

Fig. 17 Today3 macro
Fig. 17 Today3 macro

Let’s go back to our work­sheet and select cell A8, then go once again to our macro by click­ing Alt + F11. This time, we press Play (Run Sub) in our VBA edi­tor or F5 as a short­cut (Fig. 18)

Fig. 18 Run Sub command
Fig. 18 Run Sub command

What we notice here is that Excel has writ­ten the Today func­tion in cell A8 and went one cell below (Fig. 19)

Fig. 19 TODAY function and once cell below
Fig. 19 TODAY func­tion and once cell below

Let’s select a range this time and press F5 (Fig. 20)

Fig. 20 Range selected
Fig. 20 Range selected

What we’re notic­ing is that the val­ue has been writ­ten only in the active cell, although we had select­ed the whole range. Then, Excel went one cell down (Fig. 21)

Fig. 21 TODAY function and one cell down
Fig. 21 TODAY func­tion and one cell down

Sum­ming up, there is a small dif­fer­ence between rel­a­tive and absolute ref­er­ences, but still, we have to con­sid­er whether we want to use the first one or the second. 

https://www.youtube.com/watch?v=j0013EqeqNo&t