Xu Hướng 4/2023 # Unhide All Rows / Columns # Top 11 View | Hoisinhvienqnam.edu.vn

Xu Hướng 4/2023 # Unhide All Rows / Columns # Top 11 View

Bạn đang xem bài viết Unhide All Rows / Columns được cập nhật mới nhất trên website Hoisinhvienqnam.edu.vn. Hy vọng những thông tin mà chúng tôi đã chia sẻ là hữu ích với bạn. Nếu nội dung hay, ý nghĩa bạn hãy chia sẻ với bạn bè của mình và luôn theo dõi, ủng hộ chúng tôi để cập nhật những thông tin mới nhất.

This tutorial will demonstrate how to unhide all rows and / or columns in an Excel worksheet using VBA.

Unhide All Rows

To unhide all rows in an Excel sheet, we will set the Hidden Property of all of the rows to FALSE.

We can access all rows by using the EntireRow Property of the Cells Object:

1

Cells

.

EntireRow

.

Hidden

=

False

or by using the EntireRow Property of the Rows Object:

1

Rows

.

EntireRow

.

Hidden

=

False

Unhide All Columns

Similarily, we can unhide all columns in an Excel sheet, by adjusting the Hidden Property of all the Columns.

You can access all of the columns by using the EntireColumn Property of the Cells Object:

1

Cells

.

EntireColumn

.

Hidden

=

False

or by using the EntireColumn Property of the Columns Object:

1

Columns

.

EntireColumn

.

Hidden

=

False

Hide All Rows or Columns

Of course, to hide all rows or columns, just set the Hidden Property to TRUE:

1

Columns

.

EntireColumn

.

Hidden

=

True

Macro to Unhide All Rows and Columns

Use this macro to unhide all rows and columns in a worksheet:

1

2

3

4

Sub

Unhide_All_Rows_Columns

(

)

    

Columns

.

EntireColumn

.

Hidden

=

False

    

Rows

.

EntireRow

.

Hidden

=

False

End

Sub

Macro to Unhide All Rows and Columns on all Sheets

This macro will unhide all rows and columns in all sheets in an Excel workbook:

1

2

3

4

5

6

7

8

Sub

Unhide_All_Rows_Columns_in_Workbook

(

)

    

Dim

ws

As

Worksheet

    

    

For

Each

ws

In

Worksheets

        

Columns

.

EntireColumn

.

Hidden

=

False

        

Rows

.

EntireRow

.

Hidden

=

False

    

Next

ws

End

Sub

Unhiding All Worksheets Within An Excel Workbook

Although you can quickly hide as many worksheets within a workbook as you like, we’re still limited to unhiding individual worksheets one at a time – unless you’re aware of Excel’s Custom Views feature. Fortunately, there is another way to avoid the agony of manually unhiding worksheets one at a time.

In this article I’ll show you how to use a single line of programming code to unhide the worksheets. Programming code in Excel is often referred to as macros. In this case we’re not creating a permanent macro, but rather typing a line of code to run on demand.

Figure 1: There are a variety of ways to hide worksheets in Excel.

Figure 2: Unfortunately, you must unhide worksheets one at a time.

You probably don’t have the time or inclination to unhide more than a couple of worksheets in this fashion, so instead we’ll use a bit of programming code to instantly display all worksheets at once:

As illustrated in Figure 3, press Alt-F11 on your keyboard to display Excel’s Visual Basic Editor. Mac users should press Fn-Alt-F11. Although it looks like a separate program, it’s a hidden aspect of Excel that most users haven’t seen before.

Select Immediate Window from the View menu, or press Ctrl-G on your keyboard (for Mac, Ctrl-Cmd-G).

At this point the Immediate window will appear on-screen. This is a special area where any programming code you type will be executed immediately, hence the name.

Type the following line of programming code into the Immediate window exactly as written below, and press Enter.

For Each s In Sheets: s.Visible = True: Next

The downside of the Immediate Window is you don’t get any direct feedback if your programming code worked, other than seeing that all of your worksheets are now visible within the workbook. Error prompts will appear if you press Enter when the line of code is either incomplete or contains typographical errors.

You may also encounter an error if the workbook is protected by way of the Protect Workbook command on Excel’s Review menu.

You can safely exit the Visual Basic Editor once you’ve run the line of code.

Figure 3: A single line of code in the Immediate Window will unhide all worksheets in the workbook.

The aforementioned line of code utilizes Visual Basic for Applications in Microsoft Excel. This is known as an object-oriented programming language, so if you want a little insight as to what the macro is doing:

For Each sets up a loop.

s is a variable that serves as a temporary placeholder for a worksheet to be acted on.

Sheets is a collection of all worksheets within the workbook. This actually includes other types of sheets as well, meaning Chart Sheets and Macro Worksheets. We could be more specific and use the Worksheets collection instead, but Sheets results in less typing.

Each worksheet has a Visible property, and in this case we’re setting it to True. The setting gets set to False when you hide a worksheet.

Next simply instructs Excel to skip to the next worksheet in succession, until all have been processed.

If you were to store this within a formal macro, the code might take this form:

For each s in Sheets

s.Visible

Next

The Immediate Window only allows us to execute a single line of code at a time, so the colons allow us to string three lines of code together into a single line that can be executed.

How To Alphabetize In Excel: Sort Alphabetically Columns And Rows

This tutorial will teach you a few quick and easy ways to put Excel in alphabetical order. It also provides solutions for non-trivial tasks, for example how to alphabetize by last name when the entries start with the first name.

This tutorial will show you a few quick ways to alphabetize in Excel and teach how to foresee and prevent sorting problems.

How to alphabetize in Excel

Overall, there are 3 main ways to sort alphabetically in Excel: A-Z or Z-A button, the Sort feature, and filter. Below you will find the detailed guidance on each method.

How to sort a column alphabetically

The fastest way to sort alphabetically in Excel is this:

Select any cell in the column you want to sort.

Either way, Excel will alphabetize your list instantaneously:

Alphabetize and keep rows together

If your data set contains two or more columns, you can use the A-Z or Z-A button to put one of the columns in alphabetical order and Excel will automatically move the data in other columns, keeping the rows intact.

As you can see in the sorted table on the right, the related information in each row is kept together:

Filter and alphabetize in Excel

Adding a filter to your table is easy:

Select one or several column headers.

The column is alphabetized straight away, and a small upward arrow on the filter button indicates the sorting order (ascending):

To reverse the order, select Sort Z to A from the filter drop-down menu.

How to put multiple columns in alphabetical order

In case you want to alphabetize data in several columns, use the Excel Sort command, which gives more control over how your data is sorted.

As an example, let’s add one more column to our table, and then arrange the entries alphabetically first by Region, and then by Name:

To have it done, please perform the following steps:

Select the entire table you want to sort.

In most cases, you can select just one cell and Excel will pick the rest of your data automatically, but this is an error-prone approach, especially when there are some gaps (blank cells) within your data.

The Sort dialog box will show up with the first sorting level created for you automatically as Excel sees fit.

In the Sort by dropdown box, select the column you want to alphabetize first, Region in our case. In the other two boxes, leave the default settings: Sort On – Cell values and Order – A to Z:

Tip. If the first dropdown is showing column letters instead of headings, tick off the My data has headers box.

In this example, the second level sorts the values in the Name column alphabetically from A to Z:

Excel will sort your data in the specified order. As shown in the screenshot below, our table is arranged alphabetically exactly as it should: first by Region, and then by Name:

How to sort rows alphabetically in Excel

If your data is arranged horizontally, you may want to sort it alphabetically across rows. This can also be done by using the Excel Sort feature. Here’s how:

Select the range you want to sort. If your table has row labels that should not be moved, be sure to leave them out.

As the result, the first row in our table is sorted in alphabetical order, and the rest of the data is rearranged accordingly, preserving all correlations between the entries:

Problems with sorting alphabetically in Excel

Excel sort features are amazing, but if you are working with an imperfectly structured data, things may go terribly wrong. Here are the two common issues.

Blank or hidden columns and rows

An easy fix is to eliminate the blanks and unhide all hidden areas before sorting. Or, select the entire table first, and then alphabetize.

Unrecognizable column headers

If your column headers are formatted differently from the rest of the data, Excel is smart enough to identify them and exclude from sorting. But if the header row has no special formatting, your column headers will most likely be treated as regular entries and end up somewhere in the middle of the sorted data. To prevent this from happening, select only the data rows, and then sort.

When using the Sort dialog box, make sure the My data has headers checkbox is selected.

How to sort alphabetically in Excel with formulas

Microsoft Excel provides a variety of features to cope with many different tasks. Many, but not all. If you are facing a challenge for which there is no built-in solution, chances are it can be accomplished with a formula. It is also true for alphabetical sorting. Below, you will find a couple of examples when alphabetical order can only be done with formulas.

How to alphabetize in Excel by last name

Since there are a few common ways to write names in English, you may sometimes find yourself in a situation when the entries start with the first name while you need to alphabetize them by the last name:

Excel’s sort options cannot help in this case, so let’s resort to formulas.

With a full name in A2, insert the following formulas in two different cells, and then copy them down the columns until the last cell with data:

In C2, extract the first name:

=LEFT(A2,SEARCH(" ",A2)-1)

In D2, pull the last name:

=RIGHT(A2,LEN(A2)-SEARCH(" ",A2,1))

And then, concatenated the parts in the reverse order separated by comma:

=D2&", "&C2

The detailed explanation of the formulas can be found here, for now let’s just focus on the results:

In case you need to revert to the original First Name Last Name format, there is a little more work for you to do:

Split the names into two parts again by using the below formulas (where E2 is a comma-separated name):

Get the first name:

=RIGHT(E2, LEN(E2) - SEARCH(" ", E2))

Get the last name:

=LEFT(E2, SEARCH(" ", E2) - 2)

And bring the two parts together:

=G2&" "&H2

Perform the formulas to values conversion one more time, and you are good to go!

The process may look a bit complex on paper, but trust me, it will take only a few minutes in your Excel. In fact, it will take even less time than reading this tutorial, let alone alphabetizing the names manually 🙂

How to alphabetize each row individually in Excel

In one of the previous examples we discussed how to alphabetize rows in Excel by using the Sort dialog box. In that example, we were dealing with a correlated set of data. But what if each row contains independent information? How do you alphabetize each row individually?

In case you have a reasonable number of rows, you can sort them one by one performing these steps. If you have hundreds or thousands of rows, that would be an enormous waste of time. Formulas can do the same thing much faster.

Suppose you have many rows of data that should be re-arranged alphabetically like this:

To begin with, copy the row labels to another worksheet or another location in the same sheet, and then use the following array formula to put each row in alphabetical order (where B2:D2 is the first row in the source table):

=INDEX($B2:$D2, MATCH(COLUMNS($B2:B2), COUNTIF($B2:$D2, "<="&$B2:$D2), 0))

Please remember that the correct way to enter an array formula in Excel is by pressing Ctrl + Shift + Enter.

If you are not very comfortable with Excel array formulas, please following these steps to enter it correctly in your worksheet:

Type the formula in the first cell (G2 in our case), and press

Ctrl + Shift + Enter

. As you do this, Excel will enclose the formula in {curly braces}. Do not try typing the braces manually, that won’t work.

Select the formula cell (G2) and drag the fill handle rightwards to copy the formula to other cells of the first row (up to cell I2 in this example).

Select all the formula cells in the first row (G2:I2) and drag the fill handle downwards to copy the formula to other rows.

Important note! The above formula works with a couple of caveats: your source data should not contain empty cells or duplicate values.

If your dataset has some blanks, wrap the formula in the IFERROR function:

=IFERROR(INDEX($B2:$D2,MATCH(COLUMNS($B2:B2),COUNTIF($B2:$D2,"<="&$B2:$D2),0)), "")

How this formula works

The above formula is based on the classic INDEX MATCH combination used to perform horizontal lookup in Excel. But since we need kind of “alphabetical lookup”, we have rebuilt it in this way:

COUNTIF($B2:$D2,”<=”&$B2:$D2) compares all the values in the same row with each other and returns an array of their relative ranks. For example, in row 2 it returns {2,3,1}, meaning Caden is 2nd, Oliver is 3rd, and Aria is 1st. This way, we get the lookup array for the MATCH function.

COLUMNS($B2:B2) supplies the lookup value. Due to a clever use of absolute and relative references, the returned number is incremented by 1 as we go right. That is, for G2, the lookup value is 1, for H2 – 2, for I2 – 3.

MATCH searches for the lookup value calculated by COLUMNS() in the lookup array returned by COUNTIF(), and returns its relative position. For example, for G2, the lookup value is 1, which is in the 3rd position in the lookup array, so MATCH returns 3.

Finally, INDEX extracts the real value based on its relative position in the row. For G2, it fetches the 3rd value in the range B2:D2, which is Aria.

How to sort each column alphabetically in Excel

If you are dealing with independent subsets of data organized vertically in columns, you can easily tweak the above formula to alphabetize each column individually. Just replace COLUMNS() with ROWS(), make a few column coordinates absolute and row coordinates relative and your formula is ready:

=INDEX(A$3:A$5,MATCH(ROWS(A$3:A3),COUNTIF(A$3:A$5,"<="&A$3:A$5),0))

Please remember it’s an array formula, which should be completed with Ctrl + Shift + Enter:

To have a closer look at the formulas discussed in this tutorial, you are welcome to download our Excel Alphabetical Order worksheet. I thank you for reading and hope to see you on our blog next week!

You may also be interested in

How To Increment A Value By Row Or Column In Excel

Generic Formula

Expression: This is the value, reference of expression with which you want to increment. It can be a hardcoded value or any expression that returns a valid output. It should be an absolute expression (in most cases).

Number of rows above the first formula: If you are writing this first formula in B3 then the number of rows above this formula will be 2.

[steps]: This is optional. This is the number of steps you want to jump in the next increment.

The Arithmetic operator between expression and formula can be replaced with other operators to suit the requirements of increment.

So that we are familiar with the generic formula, let’s see some examples.

Example 1: Create an Auto Increment Formula for ID Creation.

Using the general formula we write the below formula in Cell B4 and copy it down.

We have replaced the + operator with ampersand operator (&) since we wanted to concatenate. And since we are writing the first formula in Cell B4, we subtract 3 from ROW (). The result is here.

Example 2: Increment the ID every 2 steps

If you want to increment the ID every 2 steps then you will need to write this formula.

The result is:

C1 contains 100.

Next we subtract 3 from it (since there are 3 rows above the 4th row). It gives us 1. This is important. It should be a hard coded value so that it does not change as we copy the formula below.

Finally the value 1 is multiplied (or any other operation) by the starting expression. As we copy the formula below. ROW() returns 5 but subtracting value stays the same (3) and we get 2. And it continues to be the cell you want.

To add steps, we use simple multiplication.

Increment Values By Column

In the above examples we increment by rows. It will not work if you copy them in the next column of the same row.

In the above formula we used the ROW function. Similarly, we can use the COLUMN function.

Generic Formula to Increment by Columns

Number of columns on the left of the first formula: If you are writing this first formula in B3 then the number of columns on the left of this formula will be 1.

I am not giving any examples as it will be the same as the above examples.

Alternative with SEQUENCE Function

It is a new function only available for EXCEL 365 and 2019 users. It returns an array of sequential numbers. We can use it to increment values sequentially, by rows, columns or both. And yes, you can also include the steps. Using this function you will not need to copy down the formula, as Excel 365 has auto spill functionality.

So, if you want to do the same thing as you did in Example no 3. The SEQUENCE function alternative will be:

Cập nhật thông tin chi tiết về Unhide All Rows / Columns trên website Hoisinhvienqnam.edu.vn. Hy vọng nội dung bài viết sẽ đáp ứng được nhu cầu của bạn, chúng tôi sẽ thường xuyên cập nhật mới nội dung để bạn nhận được thông tin nhanh chóng và chính xác nhất. Chúc bạn một ngày tốt lành!