[Article & AddIn] How to paste into a filtered range
Hello everyone, welcome to my first article in ExcelFox. :)
The question in the subject is a FAQ for decades, we all struggled about this problem at some time.
And there are different ways to overcome this, most ways I've seen in the past used workarounds.
I would like to show you a way that does not require any detours and to make it very easy to use I have written an AddIn for it, which you can download here:
https://www.dropbox.com/scl/fi/134rl...vib2qfyzz&dl=1
The actual purpose of this AddIn is to allow you to paste data into a filtered range so that only the visible cells are overwritten. This is not possible with Excel itself.
I came here because there was another very similar question: How to paste into empty cells? This thread is here:
https://www.excelfox.com/forum/showt...pty-cells-only
With a slight modification, the data can now also be merged.
The AddIn takes the data from the clipboard and 2 data structures are supported:
- XML Spreadsheet
This structure is located in the clipboard when cells have been copied. - HTML Table
This structure is located in the clipboard when a table (or parts of it) has been copied from a web page.
An installation is not necessary, simply unzip all files into a directory that Excel considers as trusted location and then open the file Paste into AutoFilter.xlam with Excel.
In Excel 2007, a PIF group is created in the ribbon in the Home tab directly next to the Clipboard group, this was intentionally kept as small as possible.
https://i.postimg.cc/TP68t9ff/Menu-Office-2007.png
After copying, Excel 2007 users must select another cell so that the paste buttons can be selected.
In Excel 2010 and above, you can find this in the context menu when you right-click on a cell.
https://i.postimg.cc/43bDq9xt/Menu-Office-2010.png
The default behavior of the AddIn is to overwrite cells, if you want to merge cells you have to choose the appropriate option. Please read the PDF file for the details.
Okay, I think that's enough to get you started if you found this article by chance and you are just looking for a solution.
Yes, the AddIn is free and I do not give any guarantee for anything. If you like it, I would appreciate a tip.
In the next few days I will explain how the code works in the following posts. If you want, you can take a look at the code; the AddIn is not protected.
I've been using the code myself for a long time, but every programmer knows that other users have different ideas. If you encounter any problems, please contact me directly.
Please do not upload the AddIn to any other place, the link above is permanent and gives you the latest version.
Until then, have fun,
Andreas.
XML Spreadsheet Number Formats
If we look at the cell with a date, we don't find a number format in it, but a style.
https://i.postimg.cc/zfxQwGVM/Paste-...ML-Format1.png
Why does Excel do this? If every cell really contained a number format with all the details, then Excel would be quite a memory hog. So it separates the number formats into their own area. I also reduce this so that we can see the important things.
https://i.postimg.cc/mDh5mW9r/Paste-...ML-Format2.png
The style "s18" is a date format, as is "s19"; as experienced VBA programmers, we recognize "s16" as the text format, but "s17" is strange.
Why doesn't this format include something like "0.00" and the currency sign?
Well, there are some named formats in Excel, which are provided differently by Excel depending on the region setting. This way, for example, all users worldwide will see a General Date adjusted to their respective region settings, without having to adjust the format of the cell! These named formats are listed in the Microsoft article for VBA.Format.
Unfortunately, the Range.Numberformat property does not accept these format names. VBA.Format doesn't help us either, we don't want to format the number, but set the number format of the cell. And I don't know of any way to read these number formats within Excel. And there are some strange ones like On/Off that can't even be formatted in Excel itself with the dialog box. That's why I use a trick.
With the AddIn I deliver another file PredefiniedFormatNames.xml, in this one is an XML structure that corresponds to a spreadsheet in Excel and the cells are formatted with one of the named formats. If you have followed my explanations so far, open this file with Notepad and look at it, then open the file with Excel, you will find it interesting.
My trick is to open this file when loading the AddIn, briefly read the number formats that Excel has used and close the file immediately.
So that the following code in the AddIn does not become unnecessarily complicated, the GetXMLSpreadsheetTables function delivers the data as a 2D array and the formats in the same size, which is, more or less, everything. ;)
So how do we get this into the target cells?