15 Jul 2014

Word - Change the default Paste behaviour

Introduction
By default when you paste Word will paste with formatting. Sometimes you don't want to do that, you want to paste just the text (no formatting) or you want to merge the formatting of what you are pasting with what you already have in your document. For me I would say that pasting as text is the most useful as it means after pasting I can decide what format I would like to apply, that's what I feel more comfortable with. That's the key really, in Word you can control how pasting works in different ways. I'll show a few of these but it's up to you ultimately how you work and which makes sense to you.


Paste Button
On the Home menu there's a Paste button. It has a number of options, 'Keep Source Formatting', 'Merge Formatting' and 'Keep Text Only'. In the example below I've written "Mary had a little lamb..." and I've added some formatting, I've copied this and one by one I'll show the three paste possibilities:


Keep Source Formatting:

The first option means that when you paste the text and the formatting will be included. This is the default option which means it's highlighted here initially and also when you press Ctrl-V this is what will happen (this can be changed, keep reading to find out how!).


Keep Text Only:

This one can be very useful, it allows you to paste just the text, with no formatting. If you will decide on the formatting later, this could be the best option.


Merge Formatting:

This adds the formatting included in the paste with what's already in your document. Personally I don't use this very often.


Right Click Paste
If you click the right mouse button you'll see the paste options on the context menu. The options are exactly the same as explained above.


Ctrl-V
Position the cursor where you want the text to go and press Ctrl-V. The default paste option will be used. This is 'Keep Source Formatting' unless you've changed the default (explained later in this article).


Paste using the Smart Tag
When you press Ctrl-V a Smart Tag will appear, click it and you have the same options as explained above.


Change the Default Paste option
Click File | Options | Advanced
Scroll down a little, you'll see the 'Cut, copy and paste' section:


Next to 'Pasting within the same document' you can change Keep Source Formatting to Keep Text Only or Merge. Click OK.


Word Version?
Both Word 2013 and 2010.


4 Jul 2014

Excel - Reference is Not Valid when refreshing pivot table data

Issue
In Excel if you click the Refresh button to update your pivot table data and the following "Reference is not valid." appears:


...this means the pivot table cannot understand the data source. Often this is because the pivot table was previously referencing a 'table' and that table (data set) has been deleted and replaced with something else, maybe another table.


Solution
Click on the sheet where the data/table is

If it's formatted as a table check the table name - on the far left

Change to the sheet where the pivot table is

Click once on the pivot table

Under 'PivotTable Tools' click Options (or Analyze if you are using Excel 2013)

Click Change Data Source

It'll ask you for the range or table name, make sure the table name is correct


Explanation
Pivot tables reference either a table name or a range of cells for their data. If you replace the data sometimes the table name or range is changed. When you try to refresh the pivot table data, Excel can't find the data because it's referring to the wrong/incorrect table name. Using the Change Data Source allows you to select where your pivot table gets its data from.

An alternative could be to change the table name to the name the pivot table is expecting. This also works well. Which method you choose is up to you.

For more information on refreshing pivot table data please see the previous article here.
http://mgxp.blogspot.ch/2014/07/excel-refresh-data-for-pivot-table.html


Conclusion
If you are using tables with pivot tables and you update the data you may have this problem. But it's easily fixed with the Change Data Source option or by changing the table name.


Excel Version?
Excel 2013 and 2010, probably earlier versions too - feel free to write in the comments below about your experiences.

Excel - Refresh the data for a pivot table

Perhaps you download a report and build a pivot table to summarise the data. You might have to do this on a regular basis, every week or month perhaps. That way you can show the most up-to-date figures. Every time you download the new data you could re-create the pivot table. It’s easy to make pivot tables of course so maybe this is fine for you? However, if your pivot table is complex or if you just want to make your life easier, why not just change the data that the pivot table uses? That’s what I’m going to explain about in this article, along with a small issue I came across that you should be wary of.

Typically one sheet (tab) in your workbook is for the data and one is for the pivot table. In the example here I will replace the table of data in the ‘DATA’ sheet with new data I’ve downloaded recently. I will then refresh my pivot table (on the ‘PIVOT’) sheet to reflect the new data.


Format as Table
It is not essential but it does help if your data is formatted as a ‘table’ in Excel. To do this click in the sheet where the data is (don’t select a range, don’t select more than one cell) and click Home | Format as Table. Select a format that you like - see the screen shot below:


Make sure 'My table has headers' is enabled:


Click OK and the data will be formatted with an auto-filter on the top and also the rows and columns will be easier to read.

Tables are great, you can do a lot with them including adding a Total Row (click Design). 


This is useful to Sum or Count column data, for example. As you use the filter the total will change. It’s a quick method or reading data, it can be useful when you just need a figure rather than to create an actual report (then a pivot table would be more appropriate).

Once your data is formatted as a ‘table’ it will have a table name. This name can be used to refer to the table data as a convenient alternative to using a range. It’s especially useful when using pivot tables because the pivot table will work from the table name rather than a range. If you update the table with more data, the pivot table will use all the data in the table, there’s no need to adjust it.


To find out what your table is called click on the table data and in the top left it will show you. Typically the default is “Table1”.


Example
There are two sheets; DATA and PIVOT


The data in the DATA sheet is over one month old. I would like to replace it with new data I’ve just downloaded from my Business Intelligence system as a CSV (Comma Separated Values) file.


Instructions
Open the new data file (in our example the CSV we just downloaded)

Press Ctrl-A to select all the data
(do not use the corner button, it selects everything, even blank cells outside of the data which means you might get 'Excel not responding' when copy/pasting. If you use Ctrl-A it selects the data only)

Press Ctrl-C – this copies all the data to the clipboard

Change to your existing Excel workbook

Change to the sheet where the (old) data is, in our example DATA

Click once on the table

IMPORTANT!!! On the Table Tools Design tab click to disable Total Rows – this is important, if you don’t do this not all the rows of data will come in.


On the DATA sheet click the corner button – this will select all the old data (Table1)

Press Ctrl-V – this will paste the new data, it will replace all the existing data in the table


Change to the PIVOT sheet (in our example where our pivot table is)

Click on the pivot table

Look at the top where it says ‘Pivot Table Tools’, click Options (Excel 2010) or Analyze (Excel 2013)

Click Refresh

The pivot table will update, taking the new data from the DATA sheet (Table1)


Check!
I do recommend that you double check that the new data has come in correctly. Check before pasting how many rows of new data you have. As I mentioned in the above, make sure that your table does not have the Total Row enabled when you paste the new data in. If you do then you may not get all the lines of new data! If you turn off the Total Rows the paste will work.


Why this way?
An alternative might be to delete all the old data and paste in the new data. This works fine but you will need to 'Format as Table' again and ensure the table name is the same as the table name the pivot table is looking for! Or you could use Change Data Source to point the pivot table at the new table of data.


Change Data Source
It might be that you want to keep a copy of the old data. In this case create a new worksheet, paste the new data into it. Format as Table – note what the table name is, typically it’ll be Table2. Go to the pivot table, click Options (Excel 2010) or Analyse (Excel 2013) and click Change Data Source, enter Table2. Now your pivot table is pointing to the new data. Follow the same steps again but enter Table1 to point it back to the original data.


Conclusion
With some care and understanding of how the tables and pivot tables work together, refreshing the data is very quick and easy.


Excel Version?
Excel 2013 and 2010, probably earlier versions too - feel free to write in the comments below about your experiences.

1 Jul 2014

Excel - Reference Pivot Table Fields using VBA

I was looking for a way to select pivot table field labels in Excel, perhaps to highlight them... I found this website that has some short, simple, (relatively) easy to understand examples: Global i Connect Excel and VBA Solutions [accessed 01/07/2014]

Ideally I would've liked to have done this using Conditional Formatting - unfortunately so far I've not found a way of referencing pivot table fields from Conditional Formatting, you always end up referring to cell references only, that's not ideal because the nature of a pivot table is that it is dynamic, the layout and composition of the data can change.

If someone knows an easier/alternative way to select and highlight labels/data in an Excel pivot table, please write in the comments below! :-)

Using Excel 2013, July 2014.