How to Remove Empty Columns in Excel with Power Query (Automated Method)

How to Remove Empty Columns in Excel with Power Query (Automated Method)

In this guide, I’ll show you how to auto­mat­i­cal­ly remove com­plete­ly emp­ty columns in your Excel data using Pow­er Query. This pow­er­ful tech­nique saves you from tedious man­u­al dele­tion and works even when columns con­tain null val­ues, emp­ty cells, and emp­ty text strings (rep­re­sent­ed by “”).

The approach I’ll demon­strate uses a spe­cif­ic Pow­er Query for­mu­la that iden­ti­fies and removes columns with no mean­ing­ful data, great­ly improv­ing your data clean­ing workflow.

Watch my detailed video walk­through of this process:

Understanding Empty Columns in Power Query

When work­ing with data in Excel, we often encounter columns that appear emp­ty but can actu­al­ly con­tain dif­fer­ent types of “empti­ness” that Pow­er Query rec­og­nizes dif­fer­ent­ly. It’s impor­tant to under­stand that Pow­er Query dis­tin­guish­es between null val­ues (tru­ly emp­ty cells), and cells con­tain­ing emp­ty text strings (“”).

An emp­ty text string occurs when a cell con­tains a for­mu­la that returns “” or when you paste such val­ues. These look emp­ty visu­al­ly in Excel, but Pow­er Query treats them dif­fer­ent­ly than cells with null val­ues. Our goal is to cre­ate a solu­tion that iden­ti­fies and removes columns regard­less of which type of “empti­ness” they con­tain, as long as the entire col­umn con­tains no mean­ing­ful data.

Importing Data into Power Query

To begin the process of remov­ing emp­ty columns, we first need to import our data into Pow­er Query. Here’s exam­ple how to do this:

  1. Go to the Data tab in Excel
  2. Click on “Get Data” → “From File” → “From Excel”
  3. Locate and select your Excel file
  4. Choose the work­sheet con­tain­ing your data (in my exam­ple, Sheet1)

After import­ing, you’ll notice that some columns might appear emp­ty but con­tain dif­fer­ent types of empti­ness — some cells might have null val­ues (shown as “null” in Pow­er Query), while oth­ers might be tru­ly emp­ty or con­tain emp­ty text strings. Our code will han­dle all these sce­nar­ios automatically.

The Power Query Solution

Rather than man­u­al­ly delet­ing emp­ty columns, we’ll use a cus­tom for­mu­la in Pow­er Query that auto­mat­i­cal­ly iden­ti­fies and removes all emp­ty columns. This approach is much more effi­cient, espe­cial­ly when work­ing with large datasets.

The Complete Code

Here’s the com­plete Pow­er Query for­mu­la that we’ll use to remove emp­ty columns:

= Table.RemoveColumns(#“Changed Type”, List.Select( Table.ColumnNames(#“Changed Type”), each List.Count( List.RemoveMatchingItems( Table.Column(#“Changed Type”, _), {null, “”} ) ) = 0 ) )

To use this code in your own projects, you’ll need to replace #“Change Type” with the name of your pre­vi­ous step in Pow­er Query. This ref­er­ence appears in three places in the for­mu­la, so be sure to update all instances.

Breaking Down the Formula

Let’s break down this for­mu­la to under­stand how it works:

The for­mu­la starts with Table.RemoveColumns(), which is the func­tion that will even­tu­al­ly remove our emp­ty columns from the table. This func­tion takes two para­me­ters: the table we’re work­ing with, and a list of col­umn names to remove.

To gen­er­ate the list of col­umn names to remove, we use List.Select(), which fil­ters a list based on a con­di­tion. We’re fil­ter­ing the list of all col­umn names (obtained using Table.ColumnNames()) to find those that meet our “emp­ty col­umn” criteria.

The core log­ic hap­pens in this part:

List.Count(List.RemoveMatchingItems(Table.Column(#“Change Type”, _), {“”, null})) = 0

For each col­umn, we:

  1. Extract all val­ues in the col­umn using Table.Column()
  2. Remove any val­ues that are emp­ty strings or null using List.RemoveMatchingItems()
  3. Count how many items remain using List.Count()
  4. Check if this count equals zero (mean­ing the col­umn is com­plete­ly empty)

If the count equals zero, the col­umn is con­sid­ered emp­ty and will be includ­ed in our list of columns to remove.

Implementing the Solution

To imple­ment this solu­tion in your Pow­er Query Editor:

  1. Click “Add Step” to cre­ate a new trans­for­ma­tion step
  2. In the for­mu­la bar, paste the com­plete code shown above
  3. Replace “#“Change Type”” with the name of your pre­vi­ous step (typ­i­cal­ly the step after pro­mot­ing headers)
  4. Press Enter to apply the transformation

You should now see your data with all emp­ty columns removed. The trans­for­ma­tion hap­pens imme­di­ate­ly, leav­ing only columns that con­tain at least one non-emp­ty value.

Testing the Solution

To ver­i­fy that our solu­tion works cor­rect­ly, we can test it with dif­fer­ent types of data. In my video, I demon­strat­ed this by:

1. Start­ing with a dataset that con­tained sev­er­al emp­ty columns (with var­i­ous types of emptiness)

2. Apply­ing our Pow­er Query solu­tion to remove these columns

3. Mod­i­fy­ing the source data to add a new col­umn with a sin­gle value

4. Refresh­ing the query to ver­i­fy that the col­umn with a val­ue is preserved

The solu­tion cor­rect­ly iden­ti­fied and retained columns that had at least one mean­ing­ful val­ue, while remov­ing columns that were com­plete­ly empty.

Advanced Usage and Adaptations

This solu­tion can be eas­i­ly adapt­ed to work with dif­fer­ent datasets. The key is to ensure you’re ref­er­enc­ing the cor­rect pre­vi­ous step in your Pow­er Query trans­for­ma­tion sequence. If your pre­vi­ous step is named dif­fer­ent­ly, sim­ply replace all instances of “#“Change Type”” with the appro­pri­ate step name.

When work­ing with very large datasets, this auto­mat­ed approach can save sig­nif­i­cant time com­pared to man­u­al­ly iden­ti­fy­ing and remov­ing emp­ty columns. Addi­tion­al­ly, the solu­tion is dynam­ic — if your source data changes and a pre­vi­ous­ly emp­ty col­umn now con­tains val­ues, refresh­ing the query will auto­mat­i­cal­ly retain that column.

Loading the Results

After apply­ing our trans­for­ma­tion, we can load the results back to Excel:

  1. Click “Close & Load” (or “Close & Load To…” if you want to spec­i­fy a destination)
  2. Choose your pre­ferred des­ti­na­tion (work­sheet, data mod­el, etc.)
  3. The cleaned data, with emp­ty columns removed, will be loaded to your spec­i­fied location

The result­ing table will con­tain only mean­ing­ful columns that have at least one val­ue. This makes your data more con­cise and eas­i­er to work with.

When your source data changes, sim­ply refresh the query to apply the same trans­for­ma­tions to the updat­ed data. The emp­ty col­umn removal log­ic will be reap­plied auto­mat­i­cal­ly, adapt­ing to any changes in your source data’s structure.

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

Excel VBA — Where is my macro | Introduction to macros and VBA 04

In this post, we will see where our macro is saved.

Excel VBA — Where is my macro | Intro­duc­tion to macros and VBA 04

Let’s go to the Devel­op­er tab. On the left, we can see the Visu­al Basic com­mand. We can also press the Alt + 11 short­cut. So, let’s click it. Now, in the worst case sce­nario, all we would see is a grey win­dow. In this case we need some more infor­ma­tion. Let’s turn on a small­er win­dow by open­ing the View menu, and select the Project Explor­er com­mand (Fig. 1)

Fig. 1 Project Explor­er command

What we should see here is all Excel files that are opened, as well as our PERSONAL.XLSB files, which are our per­son­al files for macros (Fig. 2)

Fig. 2 Files

In each file, we should also see some work­sheets and sim­i­lar things, espe­cial­ly mod­ules. Our code should be writ­ten as Mod­ule 1 by default. Before we click on it, let’s go to the View tab one more time and click on the Prop­er­ties Win­dow com­mand (Fig. 3)

Fig. 3 Prop­er­ties Window

This win­dow shows us infor­ma­tion about files or work­sheets (Fig. 4)

Fig. 4 Work­sheet information

Let’s go now to Mod­ule 1. After dou­ble-click­ing on it, we should have a small win­dow opened. Our first macro was very sim­ple, how­ev­er we have more rows than we need. We don’t need the Option Explic­it line, so let’s delete it. Next, we have the Sub key word which starts our macro and the phrase End Sub which stops it. Only the ele­ments that are between those two lines cre­ate our macro. Our macro is called TODAY. The oth­er time I men­tioned that the TODAY func­tion is a DZIŚ func­tion in Pol­ish, how­ev­er no mat­ter what ver­sion I have on my com­put­er, VBA is Amer­i­can and will use Amer­i­can names and pro­ce­dures in macros. When we look at our macro, we can see the line with the TODAY func­tion, as well as a few green lines start­ing with green sin­gle quo­ta­tion marks. They are just com­ments. In VBA, com­ments start with a sin­gle quo­ta­tion mark, and are not part of the VBA code (Fig. 5)

Fig. 5 VBA code with comments

Hav­ing the above in mind, I can just delete them and leave only the line that is an actu­al VBA code. Now, it’s quite sim­ple when you read it. ‘Selec­tion’ means that we just select­ed some­thing, a dot means the next step after select­ing. Then, we have the For­mu­la, which means that we put a for­mu­la. The R1C1 isn’t impor­tant for us. Then, our for­mu­la equals the TODAY func­tion. That is the whole VBA code (Fig. 6)

This image has an empty alt attribute; its file name is fig.-6-1024x293.png
Fig. 6 An actu­al VBA code

https://www.youtube.com/watch?v=Idag9QNODuY

Excel VBA — Recording the first macro | Introduction to macros and VBA 03

With this post, we will record our first macro!

Excel VBA — Record­ing first macro | Intro­duc­tion to macros and VBA 03

First of all, we want to open a file with macros. What we have here is a piece of infor­ma­tion that says ‘Mar­cos have been dis­abled’. You need to click the Enable Con­tent but­ton (Fig. 1)

Information concerning macros
Fig. 1 Infor­ma­tion con­cern­ing macros

If you don’t want to click the Enable Con­tent but­ton con­stant­ly, like me, go to the Devel­op­er tab, then click on the Macro Secu­ri­ty com­mand, then the Enable VBA macros radio but­ton (Fig. 2)

Enable VBA macros command
Fig. 2 Enable VBA macros command

We can also go to the Trust­ed Loca­tion part and press OK. It will also work for all files and help us with too many noti­fi­ca­tions or mes­sages (Fig. 3)

Trusted Location
Fig. 3 Trust­ed Location

Today, we want to record very sim­ple macro. We just want to write the TODAY func­tion in cell A2. This cell should be select­ed before we click the Record Macro com­mand. Since the cell is select­ed let’s write the equal sign, then TODAY, then click the Ctrl+Enter key com­bi­na­tion. It’s impor­tant to use this short­cut. That’s all we need in our first macro (Fig. 4)

 Ready function
Fig. 4 Ready function

Now, let’s delete this val­ue and then press the Record Macro. In the win­dow that has appeared, the first thing we do is choos­ing the macro name. We can use the name of our func­tion’s name. In most cas­es we should’t do that, how­ev­er our case is real­ly sim­ple. It’s only macro, not a VBA func­tion. Then, we choose whether we want a short­cut for our macro or not. If the box is emp­ty, it means that our macro has­n’t got a short­cut. If we write there a let­ter or a sign, this will mean that we have a short­cut. The Ctrl key is a default key for each short­cut. It also applies to the Shift key. That’s why, let’s hold the Shift key and press D at the same time. I’m using D, as ‘today’ is ‘dziś’ in Pol­ish. If we don’t want any short­cuts, we just press the Back­space but­ton. Next, we have the loca­tion of our macro. We have a choice of Per­son­al Macro Work­book, New Work­book or This Work­book. Let’s choose the Per­son­al Macro Work­book, as it’s the most sig­nif­i­cant one. We can also add a descrip­tion in the next part, how­ev­er, in most cas­es the name should be enough to tell us what this macro does. We have already cho­sen the name, short­cut and stor­age place, so we can press OK. You need to be care­ful when press­ing OK, because that’s the point when the record­ing process starts. It means that each action you do in this work­sheet will be record­ed (Fig. 5)

Record Macro window
Fig. 5 Record Macro window

Now, our Record Macro com­mand changed into the Stop Recording com­mand. The but­ton in the bot­tom left cor­ner of the sta­tus bar also changed. It means that we don’t need to go to the Devel­op­er tab to stop the record­ing (Fig. 6)

Stop Recording button
Fig. 6 Stop Record­ing button

Let’s write =TODAY and press Ctrl + Enter again. Then press the Stop Record­ing but­ton. It’s cru­cial to press this but­ton so that Excel does­n’t record any unnec­es­sary code. 

Now, since we added a short­cut to our macro, let’s use it in cell C2 by press­ing the Ctrl+Shift+D short­cut. Some­thing actu­al­ly appeared in the cell, but we need to change the for­mat­ting to get the date (Fig. 7)

Formatting modification
Fig. 7 For­mat­ting modification

Now, we can see that we have our date, wher­ev­er we use the short­cut (Fig. 8)

Dates
Fig. 8 Dates

https://www.youtube.com/watch?v=NBEE3mA45xg

Excel VBA — Preparation before recording first macro | Introduction to macros and VBA 02

In this post, we will work on some­thing we should con­sid­er before start­ing record­ing our first macro. 

Excel VBA — Prepa­ra­tion before record­ing first macro | Intro­duc­tion to macros and VBA 01

First of all, in the Devel­op­er tab, we have the Record Mar­co com­mand. We can also find this com­mand in the sta­tus bar on the left side. It make it eas­i­er to start our record­ing (Fig. 1)

 Record Macro command in the status bar
Fig. 1 Record Macro com­mand in the sta­tus bar

Then, we should con­sid­er rel­a­tive and absolute ref­er­ence. We have the Use Rel­a­tive Ref­er­ences com­mand. If it isn’t high­light­ed, it means that we work with absolute ref­er­ences. For exam­ple, if I select cell B9, then select cell B12, Excel will record this as ‘select cell B12′. When I turn on the Use Rel­a­tive Ref­er­ence com­mand, then select cell B9, and then cell B12, Excel will record this step as ‘go three rows down’. This issue is very impor­tant when record­ing our macro. 

Let’s click on the com­mand one more time to turn it off and work with absolute reference. 

There is one more com­mand to look into. It’s called Macro Secu­ri­ty. After click­ing it, we have a Trust Cen­ter win­dow. In the Mar­co Set­tings area, we can see an option of Dis­able VBA macros with noti­fi­ca­tions (Fig. 2)

Disable VBA macros with notifications option
Fig. 2 Dis­able VBA macros with noti­fi­ca­tions option

This option should be select­ed by default. It means that when we open a file with macros (with an xmls exten­sion), we will have infor­ma­tion that this file con­tains macro, and some code can be run with­out our knowl­edge. How­ev­er, in most cas­es, we should­n’t be afraid of this code. It’s a code which we copy from secure sources, like Google. Google is quite a secure source, as it shows you good web­sites, not dan­ger­ous ones. 

When you start work­ing with VBA, you should know some­thing about the VBA code. If you see some­thing unfa­mil­iar, you should­n’t run this code. 

I per­son­al­ly don’t like noti­fi­ca­tions, espe­cial­ly the ones that show up every time I open a file con­tain­ing macros. That’s why, in most cas­es I’m work­ing with the Enable VBA macros option. It’s not rec­om­mend­ed, how­ev­er, from my point of view it’s prac­ti­cal. I’ve been work­ing with macros for many years, and I haven’t come across any dan­ger­ous code. The most dan­ger­ous thing a VBA code has done to me is rewrit­ing my cur­rent data. 

Hav­ing the above in mind, when you run macros and you don’t ful­ly know what they are doing, you should always cre­ate a back­up copy before.

The above are the most sig­nif­i­cant pieces of infor­ma­tion you should con­sid­er before record­ing your first macro. In the next post, we will be record­ing our first macro. 

https://www.youtube.com/watch?v=L9TDg-vRC48

Excel VBA — What is a macro and enabling the Developer tab | Introduction to macros and VBA

This post starts a series about an intro­duc­tion to macros and VBA code. 

Excel VBA — What is a macro and enabling the Devel­op­er tab 

What is a macro? In most cas­es it’s a syn­onym for VBA code that we run. It’s almost the same thing. Some­times we dif­fer­en­ti­ate it and we call macros the VBA code that was record­ed by Excel — Record Mar­co com­mand. If we want to use this com­mand, we should turn on the Devel­op­er tab. In order to do that, we have to right-click on our rib­bon and go the Cus­tomize the Rib­bon com­mand (Fig. 1)

Customize the Ribbon command
Fig. 1 Cus­tomize the Rib­bon command

In the Excel Options win­dow that has appeared, we have to find the Devel­op­er tab on the right side, press it and press OK (Fig. 2)

 Developer tab
Fig. 2 Devel­op­er tab

Now, we can see that in the Devel­op­er tab we have the Record Mar­co com­mand (Fig. 3)

 Record Macro command
Fig. 3 Record Macro command

This com­mand allows us to record actions we are doing on a work­sheet, such as cell for­mat­ting, putting val­ues in a cell, size mod­i­fi­ca­tion, etc. It’s a good place to start learn­ing about the VBA code. 

Macros are good for two main reasons. 

First, they are good for repeat­ing tasks. If we want to make reports on a dai­ly basis, we can just record all actions we are doing in a work­sheet and then we are able to use it again, prob­a­bly with tiny mod­i­fi­ca­tions. We will have a report for­mat by run­ning macro. 

Sec­ond, the VBA code allows us to do the things that are not pos­si­ble or very hard when using Excel func­tions. Those things will be much sim­pler using the VBA code. It may even hap­pen that some­body has already writ­ten a prop­er code to this task. 

If we want to save macro, we have to use the ‘xlsm’ exten­sion, where ‘m’ stands for macros. We can run macros on ‘xlsx’, which is a stan­dard exten­sion for Excel, how­ev­er Excel won’t save macros in those files. Remem­ber, only ‘xlsm’ works for macros. 

https://www.youtube.com/watch?v=bUR7BQ4bglA

Extracting only letters from text

If I need to extract only let­ters from my text, what should I do? Lets find out.

Extract only let­ters from text 

When I need to extract only let­ters from my text, it means that I also need to extract spaces and enters (new lines). 

With Pow­er Query this task is quite easy. 

I need to select one cell in my table, then go to the Data tab, and click on the From Table/Range com­mand in order to take our data to Pow­er Query (Fig. 1)

From Table/Range command
Fig. 1 From Table/Range command

Here, I have four sim­ple pieces of text. One in Eng­lish and three in Pol­ish. We need to go to the Add col­umn tab, then to the Cus­tom col­umn com­mand (Fig. 2)

Custom column command
Fig. 2 Cus­tom col­umn command

In the Cus­tom Col­umn win­dow, we have the space to name our col­umn. Let’s call it Clean, and below we have the Cus­tom col­umn for­mu­la box, where we write the Text.Select func­tion. In the func­tion we need to work with text, so let’s select the right col­umn (1). Then, I need let­ters. Since there will be string of char­ac­ters, I have to use curly brack­ets, where we write upper case let­ter in the first sequence, which is “A”..“Z”. Then let’s write low­er case let­ters, which is “a”..“z”. Writ­ing two dots between let­ters means that there is a sequence. Let’s close the curly brack­et and the paren­the­sis. Now, it should be fine (Fig 3)

Whole function
Fig. 3 Whole function

After press­ing OK, the sys­tem extract­ed for us only let­ters. How­ev­er, the text pre­sent­ed like this is just gib­ber­ish. That’s why we have to add spaces. To do that, we need to go to the View bar, then select the For­mu­la bar check­box and start mod­i­fy­ing our for­mu­la. Let’s write a com­ma and a space in dou­ble quotes (1). If we need oth­er signs, we should also write them, e.g. a dot (2). As we can see, we have spaces and dots in our new text (Fig. 4)

Modifying the formula
Fig. 4 Mod­i­fy­ing the formula

How­ev­er, I don’t need dots in my text. What I real­ly need are enters. We can remove the dot from the for­mu­la and write #(lf) in its place. After enter­ing the for­mu­la, we can see that we have extract­ed enters, low­er case let­ters, spaces. But, I did­n’t extract Pol­ish let­ters. In row 4 there are strict­ly Pol­ish let­ters. In rows 2 and 3 there are some of them. The ques­tion is: how can I extract unusu­al signs from text using the Text.Select func­tion. First of all, we have to check the Uni­code. We can see that let­ters from A to Z is a sequence of num­bers from 65 to 90. It’s sim­i­lar in low­er case let­ters. The most impor­tant les­son from it is that we have a sequence (Fig. 5) 

Unicode
Fig. 5 Unicode

Now, let’s go back to our for­mu­la. If I want to have Pol­ish let­ters, I can write a sequence of “Ó”..“ż”. After enter­ing the for­mu­la, we have extract­ed also Pol­ish signs (Fig. 6)

 Extracting Polish signs
Fig. 6 Extract­ing Pol­ish signs

Now, that we have extract­ed all signs we need, we can go to the Home tab and click on the Close&Load to com­mand to trans­fer our results to Excel (Fig. 7)

Loading results to Excel
Fig. 7 Load­ing results to Excel

In the Import Data win­dow, we have to select a cell (Fig. 7)

Choosing the target cell
Fig. 7 Choos­ing the tar­get cell

As we can see, the text is writ­ten in one line, so we need to wrap it. Let’s go to the Home tab and click on the Wrap Text com­mand (Fig. 8)

Wrap Text command
Fig. 8 Wrap Text command

Now, we clear­ly see upper case let­ter, low­er case let­ter, spaces, enters. I removed signs that I did­n’t need (Fig. 9)

Final table
Fig. 9 Final table

https://www.youtube.com/watch?v=K1KgVudEtnk

Hiding scroll bars, formula bars and column headers

When we need more space while work­ing in Dash­board in Excel, we can just hide unnec­es­sary options. How? Let’s find out.

Hide scroll bars, for­mu­la bars, col­umn headers

The options we can hide are e.g. scroll bars, sheet tabs, for­mu­la bars as well as column/row head­ers. If we want to hide then we just go to the File menu and choose the Options com­mand (Fig. 1)

Options
Fig. 1 Options 

In the Excel Options win­dow, we choose the Advanced tag. If you pre­fer using short­cuts, you can press Alt + T + O, which also opens the win­dow. Lets go to the Dis­play area and uncheck the Show for­mu­la bar check­box. Remem­ber that it works for all Excel files (Fig.2 )

Show formula bar checkbox
Fig. 2 Show for­mu­la bar checkbox

Then, we can go to the Dis­play options for this work­book area. We have to uncheck the Show hor­i­zon­tal scroll bar, Show ver­ti­cal scroll bar, Show sheet tabs check­box­es (Fig. 3)

Three checkboxes
Fig. 3 Three checkboxes

We can even go to the Dis­play options for this work­sheet area where we can uncheck the Show row and col­umn head­ers check­box and press OK (Fig. 4)

Show row and column headers checkbox
Fig. 4 Show row and col­umn head­ers checkbox

We can also dou­ble-click on the Home tab to hide the rib­bon, which gives us even more space than before. 

Now, I can press Ctrl + Page Down to go to anoth­er work­book. Here, we can see that col­umn and row head­ers are vis­i­ble. How­ev­er, when we go back to our work­book by press­ing Ctrl + Page Up, we can see that there are no row or col­umn head­ers. That’s how you make more space in your Dashboard. 

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

Drop-down lists

How to add a drop-down list in Excel? It’s a real­ly sim­ple task. 

First of all, we have to have our list (1). Then, we have to select a cell or cells to which we want to add the drop-down list (2). Then, we’re going to the Data tab (3) and click on the Data Val­i­da­tion com­mand (4) (Fig. 1)

Preparing data
Fig. 1 Prepar­ing data

In the Data Val­i­da­tion win­dow, we have to select the List option in the Allow bar, then we’re select­ing the range and write it into the Source bar. Then OK (Fig. 3)

Data Validation window
Fig. 2 Data Val­i­da­tion window

Now, we have a drop-down list (Fig. 3)

A drop-down list
Fig. 3 A drop-down list

Since our cells with data are in a table, when we add a new line to the table, it also involves the drop-down list. 

Even, if we cut and paste our new data, the cells in the select­ed col­umn will still have the drop-down list. What’s more, in the newest Excel ver­sion, we have even Lookup options. We just have to start writ­ing the first let­ter of a word we’re look­ing for, then press the Tab key.

Lookup option
Fig. 4 Lookup option

This func­tion, how­ev­er, does­n’t work when we start from the mid­dle of our text. It works only with the first letter. 

https://www.youtube.com/watch?v=NMhYSgf0O3s