Skip to main content

Making Dynamic Formatted tables using Conditional Formatting




















Hello Everyone,

This time I have come up with another conditional formatting trick. The Trick is to make Formatted & Bordered tables without using any VBA Code and that too are Dimensionally Dynamic. It means you can add as many rows and columns as you want, just by changing the rows and columns attributes by changing Reference cells as you can see in the above picture. So here are the steps:-


1. Make some Rows and columns Attribute references as I have done in my example i.e. Cell B1 and B2.

2. Select a Multi Columnar Range say $4:$1048576. It would decide the Maximum No. of Rows and Columns that your Formatted Table would have. In the attached example, I have covered all full rows from 4 to 1048576 (till end). So from here on, Multi columnar range is our Base Range on which Conditional formatting applies.

3. Once selected, we will proceed for applying Conditional formatting. Go to Home Tab >>  New Rule >> Use a Formula to determine which cell to format. 

4. Write following formula there:-
=AND(COLUMNS($A:A)<=$B$2,ROWS($4:4)<=$B$1)

5. Select the desired formatting and click OK.

Explanation:-
I have used  AND Operator to cover Two Conditions that would tell Excel whether to format a cell or not. First condition is COLUMNS($A:A)<=$B$2. The Columns Function gives the no. of columns in the Range provided ie. $A:A. This Range is Dynamic Range or COLUMN Relative Range. It changes when Excel interpretates this condition in context of each cell in the Base Range, on which Conditional Formatting applies. The $A:A range changes to $A:B, $A:C and so on, when Excel considers cells going column wise to left in the Base Range.

AND

So is the case with ROWS($4:4) which is a ROW Relative Range. The $4:4 Part changes to $4:5, $4:6 when Excel considers cells going down to bottom in the Base Range. The reason I have used $4:4 instead of $1:1 or else, that the Base Range starts from 4th Row.

So COLUMNS and ROWS functions give Columns and Rows count which changes, when excel interprates their dynamic parameter ranges while going left and down on each cell in the Base Range. Now, To restrict the Formatted Table dimensions to specified number of rows and columns, I have used the conditional operators with Columns and Row Attribute References (reference cells B2 & B1).

Now when excel goes to left while interprating conditional formatting formula over each cell, it will cover only 4 columns as COLUMNS($A:A)<=$B$2 condition will return TRUE till 4 columns. Similarly, when Excel goes to bottom while interprating conditional formatting formula over each cell, it will cover only 8 rows as ROWS($4:4)<=$B$1 will return TRUE till 8 Rows. So cells formed by intersection of  4 columns and 8 rows will only fulfil the condition. Hence the desired formatting will apply on them and a table will be the result.

I hope, you will like the trick and try it. Suggestions and feedback are always invited, so do comment. 

here is the example file:-
Dynamic Formatted Tables.xlsx

Regards,
Vikas Gautam.

Comments

Popular posts from this blog

Automation:- Sending Invitation to Meeting Using Excel VBA

Hello Everyone, In one of the previous post, I wrote about automating Sending Emails using Excel VBA. This time I have come up with a pretty similar code. The code below sends Outlook Meeting Invitations to recipients on one click. here is the Code:- Sub Send_Invite_Auto() Dim olApp As Outlook.Application Dim olApt As AppointmentItem Set olApp = New Outlook.Application 'Creating Outlook Session Set olApt = olApp.CreateItem(olAppointmentItem) 'Creating an Appointment With olApt .Subject = "Enter the subject here." 'Subject .Start = DateAdd("d", 5, Now) 'Enter Date + Time here. .Recipients.Add ("example@gmail.com") 'Recipient Name, Alias, or any other Attribute. .MeetingStatus = olMeeting 'olAppointmentItem with Meeting status olMeeting 'becom

Highlighting Duplicates across multiple sheets

Hi One and All, This time I have come up with some conditional formatting stuff. The aim is to highlight the duplicates across multiple sheets and with in the sheet as well. Assumptions:- 1. I am assuming that sheet names goes on like sheet1, sheet2, sheet3.... 2. The Target Column No. is same in all the sheets. I mean, as in the attached example, its Column A which is being targeted in both sheets.

Making Password Protected PDFs using Excel Vba and PDFtk Tool

Hi Everyone, This time, I have come up a VBA Code to generate Password protected PDFs using Excel. Actually, Excel Vba has .ExportAsFixedFormat Method to generate PDFs but this hasn't any Parameter which takes password to protect the PDFs. So I have used PDFtk Tool which provide Command Line Interface to make PDFs protected using Password. Actually, You can do various things using PDFtk Tool command line varying from creating, merging, Protecting and many other. So Download the PDFtk Tool from the following link:- Download PDFtk Tookit Here are the Steps:- 1. Install the PDFtk Toolkit. 2. Use the following code to Print or Export the Activesheet with a password.