How can I create 600+ copies of a word doc, using a naming convention from a spreadsheet? - vba

I have a list of 600 names in a spreadsheet, and I want to quickly create a Word Doc for each with the name in the filename.
I work on a Mac.

Create a formula for the required commands.
The result of the formula should be:
cp "/path/to/original.docx" "/path/to/copy-filename.docx"
So for example, if you want the copy to be called "copy-" then the contents of the A column, the formula might be:
="cp ""/path/to/original.docx"" ""/path/to/copy-" & A1 & ".docx"""
Then fill down the formula down the spreadsheet to create the commands.
Then you can copy the formula result and paste it into a text editor to check it is correct. Once you are satisfied it is correct, you can paste it into a terminal window and the commands will be executed.
If this is a one-off task, this is what I suggest. If you need to do this hourly then you should probably do something different involving a VBA macro.

Related

Read formatted text file from excel with VBA

I have a huge text file with lots of numbers divided into different sections and I want to extract only certain values. It is something like this
step 1
787268 4.29430E-01
787269 4.05248E-01
787270 3.99742E-01
787271 3.99136E-01
787272 3.98422E-01
787273 3.97019E-01
787274 3.95237E-01
step 2
787268 4.29430E-01
787269 4.05248E-01
787270 3.99742E-01
787271 3.99136E-01
787272 3.98422E-01
787273 3.97019E-01
787274 3.95237E-01
I want to copy into my excel file only the two columns in the step 2 section.
So I need a VBA code that allows me to search for a particular string and after it finds it copy and paste all the raws until the next step.
Any pieces of code?
Thanks
Stefano
You can use this website to help you find what you need, a simple Google search can go a long way.
I would suggest using an if found section to find the spot where you need to copy over.
Ex.
If (Range("A1").Value = "YOUR TEXT HERE") Then
'''' COPY OVER DATA
End If

Make small changes to multiple functions without affecting cell reference

What is the best way to change ">" to ">=" in 100+ formulas such as:
=IF(INDEX($B$2:$B$46,MATCH(A3,$D$2:$D$46,0))**>**$A$2),"1","0")
=IF(INDEX($B$2:$B$46,MATCH(A3,$D$2:$D$46,0))**>**$B$2),"1","0")
=IF(INDEX($B$2:$B$46,MATCH(A3,$D$2:$D$46,0))**>**$C$2),"1","0")
Would I need some VBA code?
I would suggest one more idea if you are not comfortable doing the find and replace in excel.
Press the key combination Ctrl+` (BackQuote symbol)
Now you will have all the formulas visible in the cells.
Copy the range or columns in which you need to modify the formula
Paste it in a .txt file and then do the find and replace
Once it is done copy all the formula and paste it back to the same range.
Press Ctrl+` again and now you have got all the formulas changed as per your need
As long suggested, take a backup of your worksheet before you do these modifications
As Scott_Craner stated, a simple Find/Replace should work.
Save a version of your data in case you misjudged where the search subject is in your data.
Highlight the cells with the formulas you wish to change.
Press Ctrl and the F keys (or click on "Find&Select" in the Home tab in the "Editing" group and select Replace from the drop-down)
In the Find and Replace dialog box, make sure you are on the Replace tab.
In the "Find what:" box, type ">" without quotes (note, if there are other > symbols in some formulas, you can distinguish these with some repetitive text before and after)
In the "Replace with:" box, type "<" without quotes (note, if you included other text to specify certain instances of ">", make sure you include all the text that should also be replaced)
Hit the "Replace All" button.
Your spreadsheet formulas should now be as you'd like them. If they're not, thank goodness you saved another version first. Find/Replace is very powerful, so make sure to limit the scope by selecting the cells you want searched and being sure that Excel will find only those data you wish to change.
If you are interested in VBA, you could use it here. But Excel already has a powerful, user-friendly tool at your disposal.

Excel VBA; Search rows grabbing values and pasting them into another worksheet

I have two workbooks;
(WB1) with two sheets; "Input" and "Output"
and
(MacroWB) with the macro and a "Column Header" list.
Example file: "Messy" sheet = input, "Organized" = output
https://drive.google.com/file/d/0B-leh2Ii2uh9bDBFbDBHbGcxbUU/view?usp=sharing
I need help coding a macro to do the following:
1) Create a loop to go through each row of the "Input" sheet searching for values matching cells in the "Column Header" list.
2) When a matching value is found; take the data from the cell immediately to it's right (in the "Input" sheet) and paste it into the corresponding column of the "Output" worksheet.
3) Once every "Column Header" item has been searched/pasted for that row; move to the next row of the "Input" sheet. Rinse and repeat until all rows of the "Input" sheet have been searched/pasted.
Here is an example, the letters are to be column headers and the numbers are to be copied to the appropriate "Output" sheet column.
https://drive.google.com/file/d/0B-leh2Ii2uh9TXRGTnFDRU1jY0U/view?usp=sharing
Keep in mind that the actual data file has ~50 columns and ~3000 rows.
Also that the data is not all Letter/Numbers like the table above, it is more like the data in the linked .xlsx file.
If there is anything I haven't been clear about, please ask and I will try my best to clarify. Also I may be WAY over thinking this, if so.. please let me know.
THANK YOU ANYONE THAT CAN GET ME GOING IN THE CORRECT DIRECTION!!!
-Joe
Skip the the VBA and use Text to Columns the Data tab. I'malways copying html and its works 99% of the time. If the html is pretty and properly formated you may get away with using the fixed width option, otherwise gor for the delimted and choose "tab". If tab doesn't work try using spaces, assuming that your cells don't contain spaces.
The other option that I've had work on rare occasions that text to columns doesn't is simply saving the text in word and saving as rtf and then opening that in notepad++ (which everyone should have.) Copy from ++ to excel and that usually fixes the problem.
EDIT: If you right click before pasting and click "paste special" this regularly helps with html pasting.
In your sample file, I used the following formula in A2 of Organized sheet (assumed 50 as max columns in Messy):
=IFERROR(OFFSET(Messy!A1,0,MATCH(Organized!A$1,OFFSET(Messy!A1,0,0,1,50), )),"")
Dragging it to H11 produced the following result:
The sample data is not complete, and some 'tags' in Messy sheet are not consistent (SiteID vs SITE_ID), but it should help you get started.

How to copy conditionally formatted cells from Calc as a table into Writer

I have a LibreOffice Calc spreadsheet that uses some conditional formatting of cells. I would like to copy it into Writer as a table. The colours/formats of the cells should remain as they were due to the conditional formatting in Calc. Unfortunately when I do that, the formatting vanishes.
How can I copy it keeping the formatting?
Of course the Writer version no longer has to be conditional, but I need to keep current colours.
My work is done so eventually I can do the trick in Calc first (abandon the "conditional" part, and just preserve the formatting as - is). However due to amount of data I would prefer not to do it manually.
Is macro the only way to do that?
Use Insert -> Object -> OLE Object
Choose Create from file
Pick the right .ods file.
If you want to modify further (in my case - I need to create many tables from one spreadsheet as the original file is humongous - up to CL column) - do not tick "Link to the file" option.
After pressing OK, the spreadsheet is inserted as is (cloned and embedded), with the conditional formatting. Can be further modified (e.g. rows/cols can be deleted, hidden or whatever is needed). The conditional formatting remains active.
I personally prefer to copy as an image. This ensures the format is always exactly as it was in the spreadsheet and that no weird OLE/DDE links go wrong.
However, you specifically ask for a table. For that there are three (or 2.5) options:
Insert the entire as spreadsheet as an object. In Windows that can be done as Ister describes in his answer. This will be editable as an inline mini-sheet (Writer will invoke Calc for any editing actions).
Insert a part of the sheet as an object: Select what you want in the document, copy to the clipboard, go to Writer and select Edit->Paste Special. Then select the OLE option, or if on Linux, select "calc8". This will be editable as an inline mini-sheet.
Insert as HTML. This creates a standalone table. Formatting will not be 100% as in the sheet, as fonts, etc, will be reset by Writer, but it is a native Writer table that you can manipulate in Writer without invoking Calc. Colors, etc, are preserved.
If you use any of the object embedding options, you'll notice that formulae are kept intact (when not referring the data outside the pasted sheet or region). If you want all the data to be verbatim, then you need an intermediate step:
Select the data in your original sheet that you wish
Copy to the clipboard
Create a new sheet and place the cursor in the same spot as the first cell of the copied data (e.g. if your copied region is B4:X99, then place the cursor in B4 of the new sheet)
Select Edit->Paste Special
In the Paste Special window, check only the following options and click OK:
Text
Numbers
Date & Time
Formats

Find and Replace a lot of abbreviated text with expanded form and other text

I have multiple lists of items in Excel that are in an abbreviated form and I want to set up a macro that will automatically go through the list and replace their abbreviated form with a regular name that also includes characters so I can just run a delineated Text to Columns function in Excel that will allow me to view and sort them properly. For example:
It1
It2
It3
It4
to
Red*Category 1*Item One
Red*Category 2*Item Two
Blue*Category 1*Item Three
Green*Category 2*Item Four
All I need is a simple find and replace for each individual item and I know that I will have to create that from scratch, but each list will have the same items/categories so I don't know the best way to go about it. I am wondering if I should make one long macro in Excel listing each individual find/replace or if it's possible to do something like create an XML file with a
<find>It1</find>
<replace>Red*Category 1*Item One</replace>
and just have a macro that references it? My goal is to build one file then have a macro I can use on each list.
For the moment assuming colours are determined by font, and and using the approach here then with a lookup table as shown the results for the sample data can be achieved with the following formula (copied down to suit):
=VLOOKUP(B1,$K$1:$M$23,2,0)&"*Category "&RIGHT(A1,1)&"*Item "&VLOOKUP(VALUE(RIGHT(A1,1)),$K$1:$M$23,3,0)