+ Reply to Thread
Results 1 to 32 of 32

VBA to create new file

  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    VBA to create new file

    I am trying to create a VBA that will do the below 5 steps, but I am not sure how or if it is possible.

    1. Copy the column headers from Sheet 1 to Sheet 2
    2. Only show if column E = benign, likely benign, VUS, VUS confirmation, pathogenic, likely pathogenic (the rows in E may be variable, but E will always contain the values listed)
    3. In column G of sheet 2 combine refseq# and Sanger up until ; (semi-colon)
    4. If there is a / in column B (Sanger), then whatever letter is opposite text in front of the > symbol is used
    c.828-17G>A
    c.159C>G
    c.2339A>C
    5. column G is saved to a text file called Sanger

    I have attached a workbook where sheet 1 is the input and sheet 2 is the output, before column G is saved in a text file.

    Thank you.

  2. #2
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    cmccabe,

    Try again no attachment.
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  3. #3
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    Sorry, I attached it.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    See if the attached is what you want. YOu may need to change the worksheet names in the code to your actual worksheet name.
    You will see a Button "Click" click it and check result in sheet 2.

    Oops I should have read your request closer.
    I'll modify my code.

    If someone else steps in fine.
    Attached Files Attached Files
    Last edited by Charles; 09-04-2014 at 08:03 PM. Reason: Have to redo code

  5. #5
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    Thank you, I will wait for the modified code before downloading... have a nice weekend.

  6. #6
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    cmccabe

    Hi,

    Here's the file. You will see a button. When you click on it the data will go to sheet2.
    Sheet2 can be modified. Just let me know what needs to be change. I did not copy the "Headers" to sheet2.
    The code will send the data to the next empty row. As mentioned this can be modified.
    I had a problem with your text of "c.2339A>A/C;p.N780T". I had help on this.
    Thanks to "snb", " Rick Rothstein", "shg and "Excel Fox".
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    Thank you all very much.

    The headers are not necessary. Is it possible to save the sheet2.column G output (from the first variant to the last) to C:\Users\cmccabe\Desktop\Sanger in a file called Sanger.txt? Thank you .


    Sanger.txt
    NM_000744.6:c.1209G>T
    NM_000744.6:c.1227T>C
    NM_001909.4:c.828-17G>A
    NM_005670.3:c.159C>G
    NM_172107.2:c.2339A>C
    NM_018129.3:c.165C>T
    NM_001165963.1:c.1212A>G
    NM_001165963.1:c.3199 G>A
    NM_021007.2:c.4914T>A
    NM_000744.6:c.639T>C
    NM_000744.6:c.678T>C
    NM_006950.3:c.1321G>T
    NM_000744.6:c.1209G>T

  8. #8
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    I modified the code per you request.
    You will need to modify:
    MyFile = "C:\Users\Laura\Desktop\Sanger.txt" 'your output filename here
    The code should loop thru sheet1 and populate sheet2.
    It will then parse the strings and populate it to column g.
    It will then populate the "Sanger" text file. The code will then clear the data in sheet2.

    I tried to attach the file to this thread. But, for some reason I cannot.
    PM me you email address and I'll send it to you.

  9. #9
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    Is it possible to automatically send the newly created text file to: https://mutalyzer.nl/batchPositionConverter havethe build be hg19, the email: [email protected], and the file is the text file. Then click submit. I attached a screenshot of the page. Thank you.
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    HI,

    It might be possible. But, I'm not familiar with send or getting data from the web.
    I'll see if I can come up with a bit of code.

  11. #11
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    This is as close I can get. Not knowing the final result.
    You should start another thread requesting help on your issue.

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    Thank you very much for your help. I will start another thread, but have attached the input (Sanger.txt) and the final result (Results_141123889088.txt). I use chrome to access the site. Thanks again .
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    Hello,

    I am having trouble solving these two issues and wanted to ask for your expert help. Thank you .

    1. whatever the first item is is repeated twice in the text file (in the attached sanger.txt it is NM_000744.6:c.1209G>T - row 9 in the xlsm)
    2. in the NGS_Sanger.xlsm row 61 (c.863+2_863+3insT) does not show up in the text file (I think because the > is not found)
    Attached Files Attached Files

  14. #14
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    The problem steams from the fact that you added a new data format. The code was designed for the format in your previous examples.
    You added this format.
    I may not be able to get to this(at this time). I'm working on a large project. Perhaps another member can pick up on this.

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    Thank you .

  16. #16
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    Need to know what the data should look like. What does it key in on?

  17. #17
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    The majority of the time the data will look like this: c.1209G>T

    and sometimes included with that data is data in this format: c.863+2_863+3insT, both need to be copied over to the text file. The first case works great.


    Thanks .

  18. #18
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    I know this

    [quote]
    " c.863+2_863+3insT" needs to go to the text file.
    [quote]

    But, what is the format that you want for the txt file?

  19. #19
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    Hi,

    column F:column B

    NM_152778.2:c.863+2_863+3insT

    Does this help? Thank you

  20. #20
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    Replace your existing code with this.

    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    I added some lines of code as it could be a + or -, but the new lines are not correct (I underlined them) as no text file results. Also, the first variant that is copied to the text file is always duplicated at the start and then again at the end. Thank you for all your help .

    Please Login or Register  to view this content.

  22. #22
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    I modified the code to look for " _ ". That appears to be common. So we do not need to look for "+' "-".

    Please Login or Register  to view this content.

  23. #23
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    This varient c.863+2_863+3insT is copied, but this variant c.2508-34delG is not copied. Its possible that either could be on the data. Thanks .

  24. #24
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    Not tested. But, you can see what I'm doing. There may be other simpler ways to accomplish this.

    Please Login or Register  to view this content.

  25. #25
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    I just got around to trying out the code, it works great.... thank you . The first variant, no matter what it is, always repeats but thats not a big deal. Thanks again .

    Heres an example output:

    Please Login or Register  to view this content.

  26. #26
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    Hi,
    The code is below and the first record in the spreadsheet also gets repeated. I attached 3 examples. Thanks .

    VB
    Please Login or Register  to view this content.
    Attached Files Attached Files

  27. #27
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    The reason for the "Dup'S" was caused by the "findnext". Should have placed code to exit if the same item found in same row as first find.

    revised code I hope this helps.

    Please Login or Register  to view this content.

  28. #28
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    That fixed it.... thank you .

    I have being working on trying to make the newly created text file a name that the user inputs. So when they click on yes at the opening prompt they enter a name.
    Please Login or Register  to view this content.
    The line in the Write2Text that defines the file is:
    Please Login or Register  to view this content.
    So lets say the name Smith,Jordan was entered in order for the text file to be named that would:
    Please Login or Register  to view this content.
    work?

    Thank you .
    Attached Files Attached Files

  29. #29
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    Hi,

    Here's the code that may work.
    You may need to create some more code for it. If the user clicks "Cancel" it will exit the sub.
    Not sure how you want to handle this.

    Please Login or Register  to view this content.

  30. #30
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    Thank you .

  31. #31
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    845

    Re: VBA to create new file

    You are welcome and thanks for the "Rep".

  32. #32
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2016
    Posts
    543

    Re: VBA to create new file

    In the attached sheet (NGS_Sanger) in the Sanger column , the data can look like:

    c.165C>T; p.S55S
    c.1212A>A/G; p.V404V
    c.3199 G>G/A; p.A1067T

    The code below does a variety of things, as you no doubt remember, but is it possible to add a line that if the data in the column is in the format 1 then “hom” if the data is in the format 2 or 3 then “het” is outputted to Sanger.txt? Basically, if there is a ..>../.. then “het”, but if ..>.. the “hom”. Thank you very much . The output as is right now is also attached (Sanger.txt). Thank you.

    Desired Sanger.txt output
    NM_000744.6:c.1209G>T hom
    NM_000744.6:c.1227T>C het
    NM_005670.3:c.159C>G het

    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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. Replies: 0
    Last Post: 08-23-2013, 07:57 AM
  2. [SOLVED] Macro to create text file and write contents of selected cells to the file
    By m@cro in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-13-2013, 10:21 AM
  3. Replies: 3
    Last Post: 09-30-2011, 04:35 AM
  4. Create Check List to Delete Columns and Create New File
    By margetc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-26-2011, 05:03 PM
  5. Replies: 1
    Last Post: 07-14-2007, 07:25 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