+ Reply to Thread
Results 1 to 53 of 53

Problem with Macro to extract data from Source to Output file

  1. #1
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Problem with Macro to extract data from Source to Output file

    Hello


    please have a look at the attached two files. One is the source file with order data and the other is the output file.

    This is the code of the Macro so far:

    Please Login or Register  to view this content.

    However, there is a problem. If you look at the source file, there may be customers who ordered more than one item. If that is the case ( in my file Yvonne Hell ) the source file has additional rows for the items.

    When I run the Macro, it leaves the concerning filed empty, unfortunately.

    Can anyone help ?

    p.s. both files must not be in the same directory, or else the macro will not run
    Last edited by elgato74; 03-17-2017 at 05:39 PM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Problem with Macro to extract data from Source to Output file


    Hi !

    From Windows Explorer, double click on source text csv file : some columns are yet empty ‼

  3. #3
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Hi there

    not sure what you mean.

    SalesHistory.csv doesnt have empty columns...

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Problem with Macro to extract data from Source to Output file


    Just proceed like I wrote and of course you must see some rows have empty columns ‼

    And where in your code you open that text file ?

  5. #5
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Look at the code: you see the columns that are extracted, not all are. The problem is in Column M of the Source file.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Problem with Macro to extract data from Source to Output file


    As I don't see where in the code the source text file is opened …

    And some rows in this text file have column M empty, in particular for Yvonne Hell ‼
    Last edited by Marc L; 03-16-2017 at 09:55 AM.

  7. #7
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Ok, I made it easier to understand. See the 2 new attachments. Download the Source.xls to your desktop ( you might have to change the path ) and the Outfile file with the macro to some other location. Then run the only macro.
    Last edited by elgato74; 03-17-2017 at 05:40 PM.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Problem with Macro to extract data from Source to Output file


    Now I've an important meeting, I have to go to the swimming pool !

    It will be easier to understand with a crystal clear explanation with an attachment of expected result,
    with that I'm sure you will have more answers …

  9. #9
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Enjoy. Now I made it crystal clear for anyone

  10. #10
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Quote Originally Posted by Marc L View Post

    As I don't see where in the code the source text file is opened …

    And some rows in this text file have column M empty, in particular for Yvonne Hell ‼
    That's how Ebay gives us the data. If buyer buy more than one item, first cell is empty and underneath come the item names. Macro shall consolidate those type of entries, e.g. Yvonne Hell bought the three items ...

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    I don't know about crystal clear but here's what I've done to get some result:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  12. #12
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    ... it gives me a "Compile error - syntax error" and marks "*FPath = Sht.Parent.Path"

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    That's just so that I could run it without setting up a special folder - comment out my code and uncomment yours for both those
    "F" names

    BTW - did you add the asterisk?

  14. #14
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    I got it to work.

    However, i need the empty cell in Column F to be removed ( where the red X is ) and the customer name copied down in Column B.

    Like here:

    https://www.dropbox.com/s/qlj4ooic4b...e0003.jpg?dl=0

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    Hi elgato,

    I don't get those problems - perhaps on your input csv?

  16. #16
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Hello !

    try yourself, you will find an empty cell in Column F in the Output file. Yes, the Input has an empty cell too, but the Macro should get rid of that, that's the mission Column F may not have any empty cells ....

  17. #17
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    ... it should look like the attached file when the Macro is finished !
    Last edited by elgato74; 03-17-2017 at 05:41 PM.

  18. #18
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    Maybe:

    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Pardon my stupidity where do i put this code ? Or is this an additional macro ?

    May I ask you to post the complete Macro Code ?
    Last edited by elgato74; 03-16-2017 at 04:08 PM.

  20. #20
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    i inserted

    Please Login or Register  to view this content.
    but then it gives me an error

    "For control variable already in use" and marks "For i = 2 To"

  21. #21
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    Oops! my bad

    Please Login or Register  to view this content.

  22. #22
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    unfortunately, another error. Now "Next without For"

  23. #23
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    Oops! my bad Again

    Please Login or Register  to view this content.

  24. #24
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Nope, that does not work either. I will be posting both files again, the Source File and the Output File with the Macro

  25. #25
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    see files attached
    Last edited by elgato74; 03-17-2017 at 05:41 PM.

  26. #26
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    Well, I fixed that patch but still don't match your expected output values

    Please Login or Register  to view this content.

  27. #27
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    strange

  28. #28
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    We're probably not loading the csv file correctly!

    It's not a strong point for me.

    I'll present this to the Forum

  29. #29
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    OK ! Thank you very very very much

  30. #30
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this demonstration !


    From source text csv file and according to your post #17 attachment,
    at beginner level using the old via romana way :

    PHP Code: 
    Sub Demo()
               
    Dim CSV$, R&, SPQ$(), VA$(4), S$(), L&
                   
    CSV$ = ThisWorkbook.Path "\Source.csv"
            
    If Dir(CSV) = "" Then Beep: Exit Sub
            Sheet2
    .UsedRange.Offset(1).ClearContents
            R 
    FreeFile
            Open CSV 
    For Input As #R
            
    SPQ Split(Replace(Input(LOF(R), #R), """", ""), vbCrLf)
            
    Close #R
            
    1
        
    For 3 To UBound(SPQ) - 3
                S 
    Split(SPQ(R), ";")
             If 
    S(2) > "" Then VA(0) = S(2): VA(2) = S(4)
            If 
    S(12) > "" Then
                    L 
    1
                VA
    (4) = S(12)
                
    Sheet2.Cells(L2).Resize(, 5).Value VA
            End 
    If
        
    Next
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  31. #31
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Hello Marc,

    I like your solution, it is fast and easy, however: it does not add the comments. The comments contain the name, the street name & number, the Zip Code & City, Country and Tel Number. See my code in the very first post.

    Can you add this to your code ?

    Many thanks ! Felix

  32. #32
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    You can mod my code with your code …


    My code follows exactly your expected result from post #17 :

    Quote Originally Posted by elgato74 View Post
    ... it should look like the attached file when the Macro is finished !
    In this attachment there are only 3 filled columns ‼


    This thread has now a third page but if in your initial post you had joined a source file and
    an exact expected result workbook (already just with data without running any "code")
    you may have a quality solution from the first answer !

  33. #33
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    I tried, but i am not able to be successful

    Would you mind ?

  34. #34
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    i think the concerning code where the comments are created is this

    Please Login or Register  to view this content.

    Can you put this in your demo-code please ?

  35. #35
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Problem with Macro to extract data from Source to Output file


    As required several times, just attach a source csv file and an exact expected result according to this source file !
    If at least a true explanation was in the initial post explaining the output layout …

    Should we guess ? Of course not ‼
    No effort on your side ? Why would we do some then ?!

    As answers are at level of initial presentation, the better initial post, the better and quick solution …

  36. #36
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Thanks Marc for patronizing me. You take care of yourself.
    Last edited by elgato74; 03-17-2017 at 10:51 AM.

  37. #37
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Problem with Macro to extract data from Source to Output file


    Within my code at beginner level, during execution in step-by-step mode or via a break-point
    see within Locals window in S variable in which index (column) data are …
    Last edited by Marc L; 03-17-2017 at 10:42 AM.

  38. #38
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    I've been playing with it but I think the comments still need tweaking

    Please Login or Register  to view this content.

  39. #39
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    ... nearly there. But the comments are not filled correctly. The first 4 are correct, but then they get mixed up.

  40. #40
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    Well I reopened the source book and used your old code - perhaps we could translate into Marc L's notation??

  41. #41
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    not really. but anyway ... too much frustration for all parties I suppose. Thank you muchly indeed

  42. #42
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Bis repetita …

    Quote Originally Posted by Marc L View Post
    As required several times, just attach a source csv file and
    an exact expected result according to this source file !
    Is it so difficult ? At schoolchildren level !

  43. #43
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    no need to get personal Marc and insulting

  44. #44
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Source file and desired Output attached.

    Thanks all
    Last edited by elgato74; 03-17-2017 at 05:42 PM.

  45. #45
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Problem with Macro to extract data from Source to Output file


    For this result my code is enough 'cause there are only 3 columns …

  46. #46
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    I am sure you noticed all the comments. Those need to be filled with Data from the Source file

  47. #47
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    Still getting the comment glitch.

    Please Login or Register  to view this content.

  48. #48
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    ... time to close the thread unsolved. But thank you so much for all your time and effort ! Cheers

  49. #49
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    Unsolved and unforgotten

  50. #50
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow

    (deleted …)
    Last edited by Marc L; 03-17-2017 at 11:41 PM.

  51. #51
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb


    alerte2.gif I do not know why but within your workbook the markers of inside cells comments were not visible !
    As I can't see those markers, I can not understand as it is very not difficult to explain
    you do not expect visible texts in a Comments column but hidden within cells !

    Mod is at beginner level, just needing to warm a couple of brain neurons !
    I can't see a glitch but tell me in case of any :

    PHP Code: 
    Sub Demo4Noobs()
               
    Dim C$, R&, SPQ$(), L&, S$(), VA$(4)
                   
    C$ = ThisWorkbook.Path "\Source.csv"
            
    If Dir(C) = "" Then Beep: Exit Sub
            With Sheet2
    .UsedRange.Offset(1):  .ClearComments:  .ClearContents:  End With
            R 
    FreeFile
            Open C 
    For Input As #R
            
    SPQ Split(Replace(Input(LOF(R), #R), """", ""), vbCrLf)
            
    Close #R
            
    1
        
    For 3 To UBound(SPQ) - 3
                S 
    Split(SPQ(R), ";")
             If 
    S(2) > "" Then
                VA
    (0) = S(2)
                
    VA(2) = S(4)
                    
    Join(Array(S(2), S(5), S(9) & " " S(7), S(10), "Tel. " S(3)), vbLf)
             
    End If
             If 
    S(12) > "" Then
                        L 
    1
                    VA
    (4) = S(12)
                
    With Sheet2.Cells(L2)
                    .
    Resize(, 5).Value VA
                    
    .AddComment
                    
    .Comment.Text C
                End With
             End 
    If
        
    Next
    End Sub 
    fleche.gif Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 03-17-2017 at 11:58 PM.

  52. #52
    Forum Contributor
    Join Date
    12-05-2008
    Location
    Germany
    MS-Off Ver
    365
    Posts
    568

    Re: Problem with Macro to extract data from Source to Output file

    Never mind Marc, you do not even understand the task. Go back to your swimming pool. Fare well. Thread closed.

  53. #53
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Problem with Macro to extract data from Source to Output file

    Thanks for the rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to extract certain data from a source and reformat it
    By ZeDoctor in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-01-2016, 08:34 AM
  2. [SOLVED] Output in same worksheet as source removing source data
    By macrolearnerkk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2015, 03:50 PM
  3. [SOLVED] Output in same worksheet as source removing source data
    By macrolearnerkk in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-27-2015, 03:49 PM
  4. [SOLVED] Macro for producing output in the source sheet
    By macrolearnerkk in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-15-2015, 08:38 AM
  5. [SOLVED] Extract a few values from several .csv-files and bundle them in a single output-file
    By Jeroen606 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2013, 01:05 AM
  6. Date format problem in macro output file
    By zaska in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2012, 05:26 PM
  7. Problem in getting writing sql query output data to file
    By suhas.nehete in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-05-2008, 01:01 AM

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