+ Reply to Thread
Results 1 to 4 of 4

Looping through Columns then Rows

  1. #1
    JCP
    Guest

    Looping through Columns then Rows

    Hi Guys - I'm struggling with this. I have a spreadsheet (CSV file)
    generated from a VBA module in MSP which extracts specific data. The
    output file that I'm opening in Excel depends upon the MSP project that
    I run the other code against so, I don't know how many colunms or rows
    will be in use. What I need to do is for each row used, loop through
    each column used in that row and concatenate required cells values into
    a temporary string that I can output to a file. Then clear this string
    and move on to the next row. I can't seem to figure out the correct
    sequence of the counters and where to clear dowm the temp string value.

    Any ideas gratefully received

    Best Rgds


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

    Here is macro example you can use or modify to copy the CSV data into a text file.

    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!)

  3. #3
    John Paul
    Guest

    Re: Looping through Columns then Rows



    Hi Leith

    Thanks so much for your reply. Sorry for being slightly obtuse, but if I
    wanted to test the content of the cells for mid(<cell>,1)="c" where
    would I insert this ?- tried a couple of places including here...

    For J = 1 To LastCol
    If Mid(ActiveSheet.Cells(I, J).Value, 1) = "c" Then
    Data = Data & Cells(I, J).Value & ","
    End if

    But it fails on
    Data = Left(Data, Len(Data) - 1)

    with an Invalid proc call or arguement, thanks for your help

    Best Rgds

    *** Sent via Developersdex http://www.developersdex.com ***

  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,259
    Hello John Paul,

    From your last post it looks like you want to test the cell first before concatenating the contents. The function of Data = Left(Data, Len(Data) - 1 is to remove the final comma from the concatenated string before it is written into the file.

    Here is code with the corrections ...

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

+ 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