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
Related
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.
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.
i have a word document containing several strings. These strings have the first part always the same, for example ABC_001, ABC_002, ABC_003. I need to search for "ABC_" substring in the doc, extract all the occurences ("ABC_001", "ABC_002", "ABC_003") and copy them in an Excel sheet.
Anyone can help?
Thanks in advance.
You can reference the VBScript Regular Expressions 5.5 and regex them.
Have a look at http://www.macrostash.com/2011/10/08/simple-regular-expression-tutorial-for-excel-vba/
and http://txt2re.com/
and some of VBA multiple matches within one string using regular expressions execute method
EDIT:
Actually it is probably easier to go to data and "Get external data" choose de-limiter and import, either manually or record a macro to get a feeling for the vba structure.
This should get you all the entrys in seperate cells, then go over them with a MID to get the part you need
I really could use some help
I have two .txt/csv files that I need to read from into my excel file.
In my excel file I have a whole column, each cell containing string of characters and I need to write a script to be able find matches and and copy an adjacent column from that txt file.
An example of a single row on my txt file is shown below:
"AB101AA","AB10 1AA","AB101A","AB10 1A","AB101","AB10 1","AB10","AB10","AB","10",394251,806376,,
"AB101AF","AB10 1AF","ABERDEEN","ABERDEENSHIRE",,"ABERDEEN, CITY OF"
My excel file would have a cell which probably say "AB101AF" and i want the corresponding cell to run through a million rows and find the match and then find the corresponding nth cell on the txt file and return it on the excel spreadsheet example "ABERDEEN, CITY OF".
I know I havent been helpful in explaining the issue. But any help would be appreciated.
Thank you
Depending upon the size of your text file you could import the file using the GetExternalData option in Excel. This would allow you to load your data into a different Sheet and then use a lookup to your data from the main Sheet. Using Match and/or vlookup should help here.
You could also add a workbook connection to the text file and search using the connection.
I have an Excel sheet that I created. For this sheet it pulls in a data feed on two of the sheets. The data feed has a parameter which I populate from a Drop Down that is fed off of another sheet. I'm trying to automate this process. I want to be able to have the file run through each one of the ID's (the parameter), run the data feed, save the excel sheet, run the next ID save and so on until it goes through the list. Can someone please please help me with this? I'm new to VBA.
1) you need a list of your IDs. I like Named Ranges, so mine is named ID_List
2) Loop thru your list
dim r as range
for each r in [ID_List]
'do yer stuff here
'what needs to be done with the value **r.value**???
'how do you want to save the file each time???
next
Need some specific answers!