Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Power excel 2016 with mrexcel Master Pivot Tables, Subtotals, Charts, VLOOKUP, IF, Data Analysis in Excel 2010–2013 (Bill Jelen) (z-lib.org).pdf
Скачиваний:
4
Добавлен:
14.08.2022
Размер:
49.75 Mб
Скачать

204

POWER EXCEL WITH MR EXCEL

 

 

A similar problem is that sometimes, you might enter a function that should return a date. The formula bar will show the formula, and the worksheet cell will show the serial number.

To solve the issue, format the cell as a short date.

Here, the problem was that you entered a formula that should return a date in a cell that was formatted as General.

Gotcha: 80% of the time, Microsoft takes control and automatically formats your cell with the correct format.

Figure 500 Excel didn’t think to format this as a date.

Figure 501 Change from General format to Short Date.

Go to a blank cell and enter =DATE(2018,7,1) and Excel will automatically format that cell to convert the serial number to a short date. But, this trick does not work with any function that originated in the old Analysis ToolPak.

Bottom line: Be prepared to have to change the formatting, either from General to a Date or from a Date back to Number.

HOW CAN I TELL IF HAVE REAL DATES?

Problem: How can I tell if I have real dates or text dates? They look alike.

Figure 502 You can’t tell by looking if you have real dates.

Strategy: Go to the Formulas tab and click the Show Formulas icon. (You can also press Ctrl+`, this is the grave accent, often located on the same key as the Tilde, just below Esc on U.S. keyboards.) In Show

Formulas mode, real dates will show as serial numbers. Text dates will stay as dates.

Figure 503 In Show Formulas mode, real dates show serial numbers.

Gotcha: Don’t forget to toggle out of Show Formulas mode.

PART 2: CALCULATING WITH EXCEL

 

205

 

 

 

CONVERT TEXT DATES TO REAL DATES

Problem: I have dates stored as text. How can I convert them to real dates?

Strategy: There are three easy ways to do this.

Method 1 uses the DATEVALUE function. Follow these steps: 1. Enter a formula such as =DATEVALUE(C23).

2. Copy the formula down to all of your dates.

3. Format the results as a Short Date using the Number Format dropdown on the Home tab.

4. Copy the range containing formulas.

5. Use Home, Paste dropdown, Paste Values to convert the formulas to values.

 

Figure 504 Convert the text dates using =DATEVALUE.

 

Method 2 uses Paste Special.

 

1.

Go to any blank cell. Format that cell as a date.

2

2.

Copy the formatted cell.

3.

Select your range of text dates.

 

 

4.

Type Alt+E followed by S, then D, then Enter. This brings up the Paste Special dialog and chooses

 

 

Add from the operation section. By adding a blank cell to the text, you are forcing Excel to calculate

 

 

zero + a text date. The result is a real date. The fact that Excel brings along the format of the copied

 

 

cell is a bonus in this situation.

 

Method 3 uses Text to Columns.

 

1.

Select the range of text dates.

 

2.

Type Alt+D followed by E then F. This takes you through the default path of the Text to Columns

 

 

wizard. Excel will convert the text dates to real dates.

 

Gotcha: These methods work for 98% of the ways that people enter dates as text. There are some bizarre methods that won’t be converted. I once saw a list of events. Something that was scheduled for June 4-6 2014 was entered as 06/4-6/2014. Excel could not convert that date.

Figure 505 DATEVALUE works only if the date is valid.

Excel fails if the text refers to a date that does not exist, such as February 29, 2019. Since dates in Excel start in 1900, any dates from 1899 and back will not be converted. Also, misspellings cause the date to text conversion to fail.

If you have cells that contain month names, you can convert those to real dates by concatenating the rest of the date inside the DATEVALUE function. =DATEVALUE(A49&” 1, 2018”).

Figure 506 Convert month names to dates.

206

POWER EXCEL WITH MR EXCEL

 

 

 

FORMAT DATES

Problem: I don’t like the Short Date or Long Date format. I am going to keep storing my dates as text because I have more control.

Strategy: The ribbon is designed for people who have never used Excel. Microsoft put just a few choices in the ribbon to make Excel rookies happy. All of the good stuff is found by using More Number Formats at the bottom of the dropdown. With the Format Cells dialog, you can do almost anything with your dates.

When you choose More Number Formats, you get back to the leg- acy Format Cells dialog (Figure 384). On the Number tab, you can use the Date category to choose from 16 date formats. Most of those formats have been in Excel since the Y2K scare, so most only offer 2-digit dates.

If the date format that you want isn’t in the list of 16 formats, then choose Custom from the Number category. You can type any date format code in the Type: box. (Figure 388)

Figure 507 There are far more choices than the two date options here.

Figure 509 You can build more date formats.

Figure 508 Sixteen built-in date formats are available

under Date.

PART 2: CALCULATING WITH EXCEL

207

 

 

Here are examples of custom number codes that you can use.

That last date format uses Ctrl+J to go to a new line. After using the date format, you will have to turn on Wrap Text and make the row height tall enough to accommodate the two lines of text.

Figure 510 Custom date format examples.

FORMAT DATES AS QUARTERS OR WEEKS

Problem: Why don’t the date formats offer quarters or weeks?

Strategy: The TEXT() function in Excel will not let you display quarters or weeks. However, the FOR- MAT() function in VBA will let you display quarters and weeks. For a quick primer on setting up a VBA 2 function to use this formatting, go to your browser and search for “Learn Excel 1074”.

I realize that VBA scares people. I generally don’t include tricks in this book that require VBA. I’ve written other books that include only VBA. However, given that you can get amazing results from 3 lines of VBA code, this trick makes the cut.

Figure 511 Use a VBA function to format as quarters or weeks.

Figure 512 Three lines of code enable the Quarter and Week trick.

DISPLAY MONTHLY DATES

Problem: I have a data set that shows the actual date for each invoice. When I print the invoice register,

I would like to print just the month and year instead of the specific date.

Figure 513 Display daily dates as months in column A.