How to insert the contents of a text file into the excel sheet cell by cell? - excel-2007

I have a text file with lots of 3-digit numbers delimited by space.Now I would like to place each number from the text file into each cell in the excel sheet moving row-wise. And once the
first row is filled, the numbers should be inserted in the cells of the second row.
I tried with the 'Get External Data' From Text option under Data Tab of Excel 2007. It displays a message "The file contains more data than will fit on a single worksheet". On clicking "Yes" to import data as much it fits, the numbers are displayed in each cell of a single row until the cell XFD1. Why the numbers are not displayed in the next next rows of the sheet?
Please suggest me on how to go about achieving this.

swap the spaces with either:
Commas (,), Semi-colons(;) or tabs
to separate into columns
use
enter/return
to separate into rows
then open the file as CSV.

Related

Copy / Paste w/ Formatting from single cell to merged cells

I have an Excel sheet with multiple pages. One of two pages is a data tab and has a long list of names and then several columns of data. (Cells A1 - F1 are headers, A2-A20 are named, B2-F20 are different pieces of data regarding each name). The second page pulls specific data (index function) from the data tab.
I have bolded info on the data tab, and when you index something, you lose formatting. Normally, I could create a VBA code to copy/paste special into the format (to preserve the bolded words), but the nature of the formatting page means it has to have merged cells. I can copy/paste the info but it does not preserve the formatting. If I try to paste special, I get the error "This operation requires the merged cells to be identically sized".
Is there a way to paste and preserve the bolded text without unmerging the formatted sheet?
You can do something like this:
Worksheets("Sheet2").Range("A1").Value = Worksheets("Sheet1").Range("A1").Value
Worksheets("Sheet2").Range("A1").Font.FontStyle = Worksheets("Sheet1").Range("A1").Font.FontStyle
This will transfer the font style to the from the data cell to the target cell, regardless if the cell is merged or not.

excel vba - transferring multiline cell content to multiple rows

In Excel, my requirement is to transfer multiline cell content to multiple rows. I have attached some sample input data and output data. Please let me know on how to proceed. Thanks in advance.
Select column "name" then use Ctrl+G->bank->type "=" then hit down arrow and Ctrl +Enter-> all blank cells will be filled as shown as ur output data ( unmerge first if column "name" contains merged cells )

Concatenate entries from all incomplete rows with entries in complete rows above them

I converted a few files containing huge price lists from *.pdf to *.xls format using an online file format converter. However the conversion didn't give the desired result and more cleanup work is needed on the file. Have tried various different approaches using the macro recorder and tack overflow and have failed.
I need a macro that does the following cleanup work on my data.
Loops through rows in the selected data and Search for incomplete rows that are missing an entry in one or more cells.
Concatenate the text in these incomplete rows with the cell in the same column in the first complete row above it.
Example;
If row A contains all entries, but row B is missing entry in the Product code column then the entry in the needle description column in row B should concatenate with the needle description in row A
This file contain 10 line of data. Tab 1 shows the data that contains incomplete rows for the first 2 products. Tab 2 shows the form i want it to be in.
http://www.filetolink.com/5e39eaaf00
I'd be very grateful for any help on this for it will save me a lot of head wringing.
I didn't pull up the file because that site has extreme safety risk warnings, but the below code will do what you want as far as I can tell. If not, please clarify and I'll modify as necessary.
My Excel columns are in the following order:
ID, ProductCode, NeedleDescription
If your NeedleDescription isn't the first column to the right of your ProductCode this won't work. Just let me know what order your columns are in and I'll modify as necessary.
Copy the below into a module
Highlight the range you desire to clean up
Run the macro "Cleanse"
It will loop through all rows and fill all empty cells with the concatenation of:
CurrentRowNeedleDescription & PreviousRowNeedleDescription
Sub Cleanse()
'Fill an empty or blank cell in selection
'with formula specified
'First Highlight Affected Range, then run this macro
Dim cell As Range
On Error Resume Next
'Set formula to include in empty cells
'to be the description of existing row plus description of previous row
'Test for empty cell. If empty, fill cell with value given
For Each cell In Selection
If IsEmpty(cell) Then
cell.FormulaR1C1 = "=RC[1]&R[-1]C[1]"
End If
Next
End Sub
Hope that helps!

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.

excel macro to read text file and find matches in cells

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.