I'm looking for a simple way to recreate a relatively complex Excel sheet with a macro, inculding cell values, formulas, formatting, and cell size.
Basically, I have an Excel sheet and I need the VB code that would create the sheet. I.e. somewhat like using the macro recorder, but without having to do all the steps in sequence.
Any ideas?
(Copying from a template xls would be much more convenient, of course, but I'm limited to code and can't use additional files in production, for now).
If you don't want to use additional files, put your template as a separate sheet in the same XLS where your macro resides. IMHO, you should avoid having to recreate a complete sheet by code, at least for maintenance reasons.
Related
I made some very complex Lambda formulas which I use frequently to validate UPC Check digits, and convert UPCs from UPC-E to UPC-A format
I tried to set them up as named ranges, then save the workbook as an Add-In, and followed all the steps I could find to add that add-in into my Excel, however it doesn't look like it keeps the named ranges at all (which is where Lambda formulas are stored)
Is there any way to get around this and still save these Lambda formulas as an Add-in?
I really don't want to have to re-create the entire complex formula in a module, but it seems I may have to do that in order to have the formulas available in every workbook I open
Alternatively, if there's any way within a VBA function for me to use my existing Lambda formula, I would love that, but I'm not sure if that is possible as I know that VBA is a quite different language than Excel's formulas.
I considered making a macro which instead would just add those named ranges to my workbook, but hoping for an easier solution.
Please let me know if you have any tips for this!
What about maintaining a Template,that’s what I do, means they are there in your new books and a quick way to access them for manual copying across to existing workbooks.
2nd idea is use autocorrect to store them with a shortcut word. Autocorrect is application level and there is VBA you can find to copy your AC shortcuts to a backup workbook and reimport them if your PC crashes.
I have an excel app that modifies/delete/recreate several sheets, so formulas in other sheets that references any of those deleted sheets lose the references. What I need is to save the formulas before deleting/recreating the sheets and later restore all of then.
I wrote a couple of classes to accomplish this, one of then save the formulas as cell comments, the other one save them to a dictionary but the retoration process is very slow on both and I need to do it very fast. Thanks to all the comunity of Stackoverflow.
Pedro.
I just replace "=" with a unique text string like "xyxyxy" on all the sheets with formulae.
Then delete and replace as needed.
Then do the replace of xyxyxy with = on all sheets and the formulae work again as normal.
So I cut and paste the income statement into an excel spreadsheet, and I was hoping to make a macro that would run in a loop and check each cell one-by-one to see if they had data in it, and if it had data, to cut and paste it to another sheet.
This is the foundation of a bigger project, but I am just stuck on this. I also feel that with the looping code working, I can tweak it to do some of the other stuff I need to do.
To get started in writing a macro like this, it easiest to record the actions you're performing and the review/edit the code. When recording, perform the fewest actions as possible, including avoiding scrolling, so that the code that is generated relates to only the actions you require.
To copy and paste all data excluding blank cells, try using Paste Special and put a tick against Skip Blanks.
I'm writing a program to read some data from an OOXML Excel Workbook using Apache POI that was provided to me as example input data. There is a strange sheet named D%$&01_DevSheet at the end. It is full of formula cells with weird formulas that reference most of the other sheets in the workbook. Here is an example of one of the cells:
'Horizontal Agreements'!S15+"8I/!%4\"
It is also not visible when the worksheet is opened in Excel.
I've never run across such a sheet before. It looks like some kind of internal Excel structure. Google searches for "D%$&01_DevSheet" and "excel" "DevSheet" have turned up nothing useful.
This sheet is not present in any test workbooks I've created. However, I'm not much of an Excel user and I did not exhaustively try all Excel features.
At this point, I'm going to hard code a rule that excludes sheets ending in _DevSheet from processing. However, since this stuff is turning up in my input, I think I should understand and handle it properly, so I have some basic questions:
What does Excel use sheets like D%$&01_DevSheet for?
What user actions cause them to be created?
Are they named regularly?
What is the most reliable way of detecting sheets like this Apache POI?
Normally Excel does not use such a sheet, so it seems to be added by some specific application or tool that was used to create this Excel workbook. It seems the developer of the application stores formulas and other things in a separate sheet for separation from the user-visible content.
So likely you will need to contact/research whichever application provided this file and get more information about this sheet from there.
You can probably only exclude these sheet by name as you already did.
Suppose I have several rows of data across different spreadsheets in the same workbook and I want to display (in a separate spreadsheet) only the rows which contain a specific string. How would I do that?
Without macros this gets a little clumsy, but one way to do it is with linking and filtering.
In your separate workbook, copy all the rows from the several worksheets that might be of interest and make sure that they are linked to the source workbook or worksheets. (If you are doing all of this from within the same workbook, you don't have to worry about the external linking.)
Then apply filtering to all of these rows, and set up your filter to look for the specific string that you need.
To reiterate #Stewbob's comment, there isn't really a 'clean' way to do this using only Excel formulas and little manual work.
As I don't believe OP required the work to be done in a separate workbook, you could just copy/paste all data into an additional worksheet and filter on the desired string should get you the results you're looking for.