+ Reply to Thread
Results 1 to 16 of 16

Read whole file,Match the headers based on specific condition & write to text file

  1. #1
    macromaniac
    Guest

    Talking Read whole file,Match the headers based on specific condition & write to text file

    Dear VBA forumers and guides,

    I need a small example to guide me to read my entire excel data and match certain columns, and output certain selected columns to a .txt file. Have a file of around 300 columns and 1000 rows. (Using 2007 Excel)

    To be more clear,
    Out of my Excel sheet I want only Drive Type Date ID TagName Description QTY DID values in my text file.

    In my excel file I have a header field called DriveType and that data should be only CDD and if its anything else then reading of that row should be abandoned. (I mean the reading of other data shouldn't happen!!)

    Secondly have a set of numbers(basically frequencies) in my header file and for every no in header have a corresponding value in rows. It can be blank or some numeric value. In case my numeric value is an n or n.5 (where n can be 1,2,3,...etc) then it should be written to the .txt file else not.

    I also need to have a counter which keeps the count as to how many numeric values are found for each sale ID.(it is one of the header fileds which is important in my text file) and also need to remember the frequency where the value first occurred.

    The second part of help I need is to go about formatted output. I need the fields in the text file output to have exactly 8 characters long. (I am clueless how to do this!!)

    Brief example of my Excel data is attached.

    Hope some one can help me!!
    Thanks.
    Attached Files Attached Files
    Last edited by macromaniac; 06-06-2011 at 12:47 PM. Reason: solved

  2. #2
    macromaniac
    Guest

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    This is like the second time i have ever asked any question and please dont disappoint me... even last time I never found anyone to reply to my thread! I do not understand why!!

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    Quit whining about no-one helping & check if your question can be explained better
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    Hello macromaniac,

    Do you need all the fields to be 8 characters or only certain columns? Your description and tag name fields exceed 8 characters. Do you want to truncate these to only 8 characters?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    macromaniac
    Guest

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    Dear Royuk
    I dont mean to bring on frustrations and irritate forum contributors or admins out here. I greatly appreciate you guys for all the help you provide was little frustrated as no one even replied to either of my posts! I am sorry I was under pressure at work!
    I hope you understand.

    Thanks,
    macromaniac

  6. #6
    macromaniac
    Guest

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    Dear Leith Ross,

    Thanks for looking at my question. Well I am sorry for not been clear about my problem. This is the first time ever I am doing it so please bear with me!

    I am concerned about the headers Date ID, DID and all the numbers in my headers.

    Wanna just read those columns print them out to the text file starting with "+" at beginning of each line in text file.

    I greatly appreciate your help.
    Thanks,
    Macromaniac

  7. #7
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    Alright, this may need to be worked on but it is a start.

    Please Login or Register  to view this content.
    I borrowed the fnum part from here and am not entirely sure how to declare fnum if Option Explicit is used.

    I have also uploaded a copy of your workbook which uses a Button object for a quick run of the Macro.

    Good Luck.
    Attached Files Attached Files
    Last edited by Mordred; 06-02-2011 at 05:31 PM.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  8. #8
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    After playing with this a bit more, perhaps you want to append to the file instead. If so change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    I hope you realize your 'question' consists of 5 questions. So to me it seems to be more a project than a question.
    What's your experience with VBA ?



  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    Quote Originally Posted by snb View Post
    I hope you realize your 'question' consists of 5 questions. So to me it seems to be more a project than a question.
    What's your experience with VBA ?
    Zero I would say

  11. #11
    macromaniac
    Guest

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    YEp as Royuk has mentioned I have no experience!!

  12. #12
    macromaniac
    Guest

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    Quote Originally Posted by royUK View Post
    Zero I would say
    You dont have to be scornful about my experience.. Well I am new to the whole world of programming. Yep I know its hard but I am sure there is a beginning in everyone's life. And yeah I am in that stages right now. I did mention it in the post when I put my question across. I agree I was frustrated as initially no body replied and I was under pressure of doing some stuff here. That doesn't mean I intented to hurt anyone, I did apologize to you that day itself. Kindly dont be scornful. You are learned and I respect that fact. do not make fun of me.

    Thanks & regrads,
    Macromaniac

  13. #13
    macromaniac
    Guest

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    Dear snb

    Yeah I do realize that is not a way to ask any doubts. I am new and I was clueless how to even put it across. I have no experience in whole of programming and I am new.
    I am new to everything and this was the first time I ever posted any quetsion online in any forum. I hope you agree everyone has a beginning and mistakes happens. I am in that phase that doesnt mean to say peoplewho are learned should ridicule me.

    I am aware I did loose my patience and posted few things which I should not have! But I did apolgize for the same behavior many times.Please dont be scornful.

    Thanks,
    Macromaniac

    Quote Originally Posted by snb View Post
    I hope you realize your 'question' consists of 5 questions. So to me it seems to be more a project than a question.
    What's your experience with VBA ?

  14. #14
    macromaniac
    Guest

    Smile Re: Read whole file,Match the headers based on specific condition & write to text fil

    Dear all,

    I once again personally thank Mordred for taking time out and for helping me out.
    Its a great ton of support and encouragement I have recieved from this forum.
    And sorry to all the people whom knowingly or unknowingly have irritated. Its just because of some mistake. Kindly forgive me and I greatly appreciate all the help I have received from the members here who depsite their busy schdules try to solve problems of people like me.

    Mordred you are simply AWESOME!!

    Thanks again,
    Macromaniac
    Last edited by shg; 06-06-2011 at 05:49 PM. Reason: deleted spurious quote

  15. #15
    Valued Forum Contributor Blake 7's Avatar
    Join Date
    10-01-2010
    Location
    Bogota, Colombia
    MS-Off Ver
    Excel 2010 64 bit and Excel 2007,
    Posts
    1,377

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    Quote Originally Posted by royUK View Post
    Quit whining about no-one helping & check if your question can be explained better
    loooooooooool !
    Blake 7

    If your question has been answered, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

    If any member's response has helped to solve your problem, please consider using the scales icon on the top right of their post to show your appreciation.

    http://failblog.org/

  16. #16
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Read whole file,Match the headers based on specific condition & write to text fil

    He actually joined as a different ID - new2vb, to post negative rep & complain.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1