+ Reply to Thread
Results 1 to 5 of 5

filter data from txt file

  1. #1
    Registered User
    Join Date
    06-26-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    filter data from txt file

    Why isnt this script working. I just want the company names.

    Please Login or Register  to view this content.

    sheet looks like this:

    Down Column A

    Company Name
    Pizza

    Company Name
    HotDog

    Company Name
    Salad

    Company Name
    Phone

    etc.....

    it'll output the first three company names( hotdog, pizza,...) ..skip the next 2 and then pick up and skip again.


    Thanks in advance
    Last edited by pike; 06-26-2010 at 07:24 PM. Reason: title for newbie pm warning

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

    re: Not all data is written to text file using loop

    Please Login or Register  to view this content.

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

    re: Not all data is written to text file using loop

    Hello eherr9633,

    The problem with the code is MyRow = MyRow + 1. MyRow is the control index value for the loop. It is a bad programming practice to modify this value. The If statement determines if the cell contents are to be written to the file. There is no need to increment the control index value because the loop does that for you. Here is working version of your macro...
    Please Login or Register  to view this content.
    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!)

  4. #4
    Registered User
    Join Date
    06-26-2010
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Not all data is written to text file using loop

    That makes absolute sense I am cannot believe I over looked that!!

    Thanks a lot


    Quote Originally Posted by Leith Ross View Post
    Hello eherr9633,

    The problem with the code is MyRow = MyRow + 1. MyRow is the control index value for the loop. It is a bad programming practice to modify this value. The If statement determines if the cell contents are to be written to the file. There is no need to increment the control index value because the loop does that for you. Here is working version of your macro...
    Please Login or Register  to view this content.

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

    Re: filter data from txt file

    There's no need for a loop as you can see in this maybe overlooked this suggestion.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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