Import Text File Using VBA And Remove The Duplicate Headers?
Mar 8, 2014I have a few text files and i want to import them into excel using VBA. I am herewith attaching the sample text file and the desired output file.
View 14 RepliesI have a few text files and i want to import them into excel using VBA. I am herewith attaching the sample text file and the desired output file.
View 14 RepliesI have a comma delineated text file that is full of stock item details such as stock code, description, 3 different prices etc it is about 15 fields wide by about 400 rows down. I need to be able to import all rows but only certain columns into an excel worksheet using vba. I know I can easily just rename it to .xls or .csv or something like that but its a text file we export out of our system at work and we need to be able to give it to customers who then can import into this excel spreadsheet/calculator I am creating.
The file looks something like this:
"String 1", ""String 2", "String 3", "String 4", ...... all the way up to 15
There is 400 or so rows (which represent stock items)
Now I need to copy all rows in column 1 (string 1) all rows in column 12, 13, 14, 15 (This is the only data I need from the text file in this particular spreadsheet/calculator)
I have it working fine reading the entire row in one at a time splitting it up into a string array using the Split() function and then only copies the certain array indexes i need into the worksheet here is the code for this: ...
I am importing a csv file and each field in this file is imported with an apostrophe
eg: '01
I need to remove the apostrophes but leave the information as text thereby keeping my leading 0's
have tried formatting as text
data text to columns
nothing I do works.
I have the following two columns, and would like to obtain for each individual Company, the corresponding Country values excluding duplicates as text in a single cell.
Company 2Country B
Company 2Country C
Company 3Country C
Company 3Country C
Company 5Country A
Company 5Country C
Company 5Country C
For example:
- For Company 2, a cell containing "Country B, Country C"
- For Company 3, a cell containing "Country C"
- For Company 5, a cell containing "Country A, Country C"
I've approached generating an array using an IF statement, as in =IF(INDEX(A1:A8="Company 5",,),INDEX(B1:B8,,)," "), which returns the following array: ={" ";" ";" ";" ";" ";" ";" ";"Country A";"Country C";"Country C";" ";" ";" ";" "}.
The question is: how do I get that array to produce, as text in a cell: "Country A, Country C". Note that the duplicate Country C has been removed.
There are a few "StringConcat" User-defined functions that I've found elsewhere on the internet, but they don't seem to be able to handle to conditionally generated IF Index array, which I would think is key to parsing between Countries corresponding to each Company in the list.
I have a workbook with many spreadsheet named Sheet1, Sheet2 and so on. Each sheet is filled completely upto 65536 rows. This data is being picked up from a CSV file. In this file there are sites with each site there is a assciated set of data. What happens is the data that extracts data does not differntiate between sites and when it reaches to the end of worksheet it splits the data into next sheet. So I am trying to create a macro to check each spreadsheet starting with the last sheet in the work book for example last sheet in the workbook is seven it should go to sheet6 and if there is a blank row after row 64000 it should cut all the rows and move them to sheet7. Then it should goto sheet5 and do the same and keep on doing it until it reaches sheet1.
View 9 Replies View RelatedGot a slight problem; I am making a "worker-plan", where you should be able to write a name on one file and have it updated (removed) from the equivalent columns on another file automatically. Here's an example with two separate projects:
Project 1 before and after changes:
Attachment 257366
Attachment 257367
Project 2 before and after changes:
Attachment 257368
Attachment 257369
You can see here how I intended it to work. When one worker is moved from Project 1 to Project 2, that worker should also be removed from those weeks in Project 1. The previous worker from Project 2 should also be removed from those weeks (in Project 2).
Are there any formulas that can make this work automatically? All week numbers will belong to the same columns in all files.
Edit: There are 30 files that should be syncronized, not just two.. I could also gather all files into one file with sheets, instead of having seperate files.
I have a macro which imports data from a mainframe dump text file and performs 'Text to Columns' on the imported data so that formula in the spreadsheet can act on the data. The code works perfectly well when I use it, but if a different user logs on and performs exactly the same mainframe dump and import macro the Text to Columns action splits the raw data in a different way and the result is that the split renders the formulae useless.
I've experimented a little and for some reason it appears that the 'Field Info' parameters which are produced when the Text to Columns function is recorded in a macro differ between users even though the raw data is exactly the same.
FieldInfo:= _
Array(Array(0, 1), Array(18, 1), Array(35, 1), Array(56, 1), Array(70, 1), Array(88, 1), _
Array(102, 1))
I have a long list of around 400 phrases, all in their individual cells. My problem is some of the terms have duplicate words in them.
Here's an example: [URL]
Is there any way to remove this duplicate text from the cell?
I have a large worksheet and I managed to duplicate data in a row of cells.
MOT 1/F1,
B/P 1f2,
B/P 1f2
In the string above I need to delete all text from the first comma to the end of the string so the above would look like:
MOT 1/F1
This is an example in one cell of many. The text prior to the first comma may or may not repeat and it is the only portion of the text I wish to keep. The first comma is not always in the same place (character count position).
I am about to re write my vba project as I can see that I need to make it more robust. One of the main issues I have is that the source XML file is not controlled by me. The quality and content is consistent but sometimes the order of the columns is different. At the moment that totally throws out my macro as it relies on certain columns for certain functions.
Trying to nut out the best way to import an XML file, keep only the specific columns I want - by content not location so then all follow on formula's will work and reference the correct data.
I have one theory that I can't get going. I thought if using defined names based on column headers this would allow me to keep and sort the columns I want. I can't find any examples to support this. I have been looking at the advanced filter but most examples reference exact cells which isn't flexible and leaves open to wrong data being pulled. Since I can't control the source doc what can I do?
I have a nice little code which imports data from a mastersheet to my input sheet. Though it will only work as long as the mastersheet is static.
I'm trying to match the product code in column A between my mastersheet and my workbook with a input sheet. And then copy the cell value in column D and E of the relevant row.
The messy part is that some of the products are split into sub categories (less than :$$$:, between :$$$: etc) and they dont have any info in column A.
I'm unsure if this is doable. Is it? And if I get permission to edit the mastersheet somewhat.
I tossed in the start of my currect static c/p, thought I don't think I'm keeping it if I get a handle on this match macro issue.
Code:
Dim ws As Worksheet, wb As Workbook, t As Date, wb1 As Workbook, wb2 As Workbook, wbName As String, janei As String, spm As String
Dim fil
Set wb1 = ActiveWorkbook
ChDir ""
[Code] .........
I have a lot of txt. files you would like to imported automatically via VBA code text file is always the same need only certain data in these two rows which is the red just want this data
it is copied from txt. files in Excel so that I had with the click of a button you obtain all the information and through this button you looking for the folder in which the data next would have 2 lines one would be the computer name of one folder and the user can more This would also be the folder in which the data were computer name to the main folder subfolder, users, and wanted to let me read the particulars of which are in the name of the computer and the user. for example. computer name of the user
i have in excel what i need
I recorded the following macro but it only imports files with a specific name. Can someone change the code to allow it open the specific file loaction where I may choose which .txt file I want to import.
View 3 Replies View RelatedI've a large text file which I need to import selected information only.
Below is the sample text file which showing profile for 3 item.
I have imported a tab delimited text file into excel. One of the columns consists of a string of text - a comment section. Within this column, there are periods and for some reason it seems that Excel is treating these periods as row separators. how I can prevent Excel from separating the text into rows?
View 3 Replies View RelatedI have about 100 text files from which I need to import specific sets of numbers into excel. The part in the file looks like this
Mg24(MR)1917.4198.5
Mg25(MR)250.453.6
Mg26(MR)264.464.2
I need to import the numbers in the 1st row but they need to be transposed. and than of cause I need to do that for the other 99 files I have.
I am a noob to VBA, and not much of a programmer either.
I know how to import a simple text file into excel, but this time I have something more complicated.
I am trying to figure out a problem. So far without any results. As an Intern at a company, every week I receive a .txt which I have to import and reformat in Excel. Every week this means several hours of work, so I decided to see if this process could get automated. Or at least partially. I was wondering if any of you could give me a hint how to do this, or where to start. Attached you will find the raw .txt data and the format it should get in Excel.
View 3 Replies View RelatedThe Workbooks.OpenText works for me, but I need to import the text file into one worksheet of an existing workbook. Is there a method to do this?
View 1 Replies View RelatedI am trying to import a range from a txt file that is not opened. It would be in cell AM2 if opened in excel, or it would be the 38th tab of the 2nd row.
I have it working by opening the file copying the cell and pasting into the destination cell. but I have this looped for each text file in a folder. this takes a very long time.
How can this be done faster? I have been trying to figure out how to use For input as ... but haven't been able to grasp how to manipulate the code.
I need 3 columns - Title - HD - Channel. If no value for HD, the field would be blank.
Data looks like this in txt file:
> A&E HD 265
> ABC Family HD 311
> Altitude Sports and Entertainment HD 681
> American Movie Classics (AMC) 254
> Animal Planet HD 282
> BBC America 264
> BET Jazz 330
> BYU TV 374
> Big Ten Network HD 220
> Black Entertainment Television (BET) 329
> Bloomberg Television 353
> Boomerang 298
Needs to look like this in Excel
> Should look like:
> A&E HD 265
> ABC Family HD 311
> Altitude Sports and Entertainment HD 681
> American Movie Classics (AMC) 254
> Animal Planet HD 282
> BBC America 264
I have a large text file, 75mb, that I would like to import into Excel but it goes well beyond the 65536 lines available.
Is there a process to get these files into excel? File splitter?
Can we create a macre that can convert txt file into excel.
View 5 Replies View RelatedI have a software application that imports audio files and writes information about these files to text files. I'm trying to write and Excel/VBA application that will parse and import the data contained in these files. find a sample of one of these files attached. The big hurdle I am facing is I cannot figure out how to parse this file - the delimiter keeps changing as throughout the file (see example below):
otrk ´ptrk ¬
otrk Îptrk Æ
otrk Ôptrk Ì
otrk âptrk Ú
otrk *ptrk "
otrk Øptrk Ð
otrk þptrk ö
otrk ´ptrk ¬
otrk ptrk
otrk Ðptrk È
otrk Þptrk Ö
otrk þptrk ö
otrk ptrk
otrk îptrk æ
otrk ptrk
I have this text file that gets sent to me, and i want to be able to re-organize the horible set up (see Import tab) into the proper format (see Reorganized tab) using Macros. There are many variables, such as the number of part numbers, the number of problems can all vary. As well as the number of claims. I don't even know where to begin. See attached file as a sample.
View 4 Replies View RelatedI found this question from 2004 but it has expired so I could not quote or reply to it. It can be found at Open file search and import text file This was the question:
I'm looking for some code that i can attach to a command bar which allows the user to browse and search for any text file on their C:Drive and then import it. I think i can work out the import using the data import wizard and macro recorder.
Sub DoIt()
Application.Dialogs(xlDialogImportTextFile).Show
End Sub
The original person said they can work out the import using the wizard, but my users are not tech savvy and therefore I was wondering if I could automate the text file showing up in the excel sheet ( named 'Import') after selecting the text file (instead of going to the wizard). I have attached a sample text file for an example (first row being a header)
I'm back to ask the gods how can I import data from a .txt file every 2 minutes without me actually hitting refresh everytime? Is there some code that will import it or that will refresh it every 2 minutes?
View 7 Replies View RelatedI have a text file and need to convert into excel output using macro with a few selection item. Im attached a text file at least u know what how the text file look. In the text file, please ignore the 1st page(introduction page). In page 2 onward, what i want macro to run is to sort the items to excel into each column like 'BOOKINGNO',P.DELIV','CNTRNO','TYPE','INCOMING VSL','VOY','L. PORT'.
View 6 Replies View RelatedI'm trying to automate an Excel macro. I need a way to select the latest .txt file from the Import Data dialog box.
I currently have a "CHDIR" at the beginning of the macro that sets the active directory. When I make the "Import Data" pick I am in the proper place. Now if I can only sort the list of .TXT files by date, select the first file in the list and hit ok to continue I'd be off and running.
I'm trying to import a text file with an Excel 4 macro. I tried the Open.Text function but I cant assign a date (YYYYMMDD) format to the first field.
View 4 Replies View Related