+ Reply to Thread
Results 1 to 46 of 46

Using option buttons to import data from Notepad

  1. #1
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Using option buttons to import data from Notepad

    Dear All

    I am new to VBA. I need to import data from Notebad using option buttons. Every time the user chose one of the option button the related data should be uploaded to the same range of cells in the worksheet.

    I really looking for help
    Thanks in advance
    Last edited by TallOne; 02-22-2012 at 09:45 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363

    Re: Using option buttons to import data from Notebad

    Hi

    Can you provide a sample of the text to be upload, is it always the same format...
    Denis

    Please always attach the sample workbook without sensitive information when asking for help

    To add a module
    Press Alt + F11 (this is the Visual Basic Environment)
    Insert Menu, select Module
    Past code there
    Close Visual Basic Environment (X)

  3. #3
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notebad

    Thanks for your reply jetted.

    Yes It always the same format. I have tried to attach my files, but I always get an error msg. I will try again to upload them.
    Thanks again.

  4. #4
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hey all
    Here are my files that need to be imported to Excel


    Cdeastm.txtCdeastf.txtCdnorthf.txtCdnorthm.txt

  5. #5
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    I really looking for your help, plz

  6. #6
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Plz. help me, really looking for your help..

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using option buttons to import data from Notepad

    Hi,

    What is the delimiter? just a space? And do you want to pick the files or all the files in a folder?

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  8. #8
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi Abousetta

    What I need is that, when the I click on one of the option button, the file attached to the button should be imported to Excel, and if I clicked on other option button, data should be replaced by the new file that I have chosen.

    I really thank you for your help.

  9. #9
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using option buttons to import data from Notepad

    Hi,

    So in other words, you want a button that when clicked, will prompt the user for a text file. That text file will be imported into the same place in Excel overwriting whatever was there before. Is this correct so far?

  10. #10
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi Abousetta,

    Sorry for this delay. Yes that is exactly what I need. Thank you for your help.

  11. #11
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using option buttons to import data from Notepad

    I had to amend the normal way I would import the files because your data sometimes has several spaces between entries.

    Have a look at the attachment and let me know if it suits your needs.

    abousetta
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi Abousetta

    I really appreciate your help. Let me look at it, and understand the code and I will let you know. Many thanks for your reply and help.

  13. #13
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using option buttons to import data from Notepad

    It simply opens the text file, using space as the delimiter (details can be found here), copies the data over to the original worksheet (with the button) starting at cell "A2" and then closes the text file.

  14. #14
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using option buttons to import data from Notepad

    Wrong thread.. need sleep..
    Last edited by abousetta; 02-23-2012 at 06:17 AM.

  15. #15
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi Abousetta

    Is it possible to modify it so that when the button clicked (Sheet 1, for example), will prompt the user for a text file. That text file will be imported into the same place in Excel (in Sheet2, for example), overwriting whatever was there before.

    Many thanks for your help.

  16. #16
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi Abousetta

    I think I have managed to modify your code, so that I can import my data to another sheet. But I still have question: Is it possible to show the file name that have been chosen, just near the button?

    Thanks a lot for helping

  17. #17
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using option buttons to import data from Notepad

    Possible, just changed ActiveSheet to Sheets(2)... in other words instead of the activesheet where the button is, we are directing the paste into the second sheet of the workbook. If sheet is a worksheet then there should be no problems. Do you need a new copy of the workbook or can you manage from here.

  18. #18
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Sorry for this.

  19. #19
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using option buttons to import data from Notepad

    No problem. I am going to upload a new copy (and then head to bed). If you have any further tweaks you need, just let me know and I will get to them as soon as I can.

    Good luck.

    abousetta
    Attached Files Attached Files

  20. #20
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    I really appreciate your help Abousetta. My next question is that: Is it possible to use a combo box (with file names) instead of button, so that each time I chose a file, I knew its name.
    OR
    Is it possible to show the file name that have been chosen, just near the button, if I am gonna use button instead of combo box.

    Your help are highly appreciated.

  21. #21
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi all
    I'm still struggling with the following question:

    "Is it possible to use a combo box (with file names) instead of button, so that each time I chose a file, I knew its name.
    OR
    Is it possible to show the file name that have been chosen, just near the button, if I am gonna use button instead of combo box.

    Your help are highly appreciated.

  22. #22
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi All

    I have managed to deal with a combo box. Thanks for your help.
    But I have another question:

    Is it possible to load two files at the same time to different sheets (in other words, if I chose the file "filename.f" I need the other file with the same name and different extension "filename.m" to be imported to a different sheets).

    Looking for your help

  23. #23
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Any help, plzz

  24. #24
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using option buttons to import data from Notepad

    Hi,

    Put this code before the end of the macro:

    Please Login or Register  to view this content.
    That will put the full path of the file you just imported into cell P1

  25. #25
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi Abousetta

    Thanks a lot, your help is always appreciated.
    I used a combo box instead of button. So now my question is:
    Is it possible to load two files at the same time to different sheets (in other words, if I chose the file "filename.f" I need the other file with the same name and different extension "filename.m" to be imported to a different sheets).

    Thanks in advance

  26. #26
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using option buttons to import data from Notepad

    Could you upload the workbook (or a dummy with similar structure) so we see what you are after. I haven't worked much programming combo boxes before but it shouldn't be too difficult (I hope).

  27. #27
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi Abousetta

    I have attached a dummy workbook. What I need is that, to be able to import two file with the same name but different extension to different sheets in my workbook, for example, If I click on a, it should import two files (a.f and a.m) to different sheets in my workbook.
    Attached Files Attached Files

  28. #28
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Any idea..

  29. #29
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Using option buttons to import data from Notepad

    I can't seem to get the syntax right so I will pass this off to anyone else who is familiar with the properties of a Combo Box

  30. #30
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi Aboustte, I really appreciate your help, thanks a lot.

    I tried to sort it out, but no succeed

    You really helped me.

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

    Re: Using option buttons to import data from Notepad

    Perhaps using an ActiveX combobox is in order for this problem. See attached.
    Attached Files Attached Files
    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---

  32. #32
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi Mordred

    Thanks for your help. I really appreciate it.

    But the macro doesn't work !!

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

    Re: Using option buttons to import data from Notepad

    Hi TallOne, can you be more specific? It works for me so if you can say where the error is perhaps I can help.

  34. #34
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi Mordred

    Sorry for that, it was my mistake. It works now. Thanks a lot for helping me. If I may ask you again!

    Is it possible to do modify your code, so that I can import my data from workbook (with the data represented in different sheets) instead using text file. And again when I import, say, (cdeastm) the other sheet (cdeastf) should both be imported to different sheets in another workbook.

    Thanks in advance.

  35. #35
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi All

    I really been trying hardly to sort out the above question, but no succeed. The question is as follow:

    I have different data files in notepad (and I made a copy of it in workbook, in different sheets), I want to import these data to my workbook using a combo box. The problem is when I import, say (cdeastm) to sheet2, I need the file named (cdeastf) to be imported to the same workbook, but in sheet3.

    Please I really need help on this.
    Thanks in advance..

  36. #36
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,627

    Re: Using option buttons to import data from Notepad

    I have modified Mordred's effort:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Ben Van Johnson

  37. #37
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi ProtonLeah,

    Thanks a lot, I really appreciate your help. It works perfectly. Thanks again. Is it possible for the sheets to be updated each time, instead of copying to new sheets.

    Thanks a lot again...

  38. #38
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi all.. Any help please...

  39. #39
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi All

    I have been trying to do sort this task, but I really couldn't. Plzzzz any help...

  40. #40
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,627

    Re: Using option buttons to import data from Notepad

    Is it possible for the sheets to be updated each time, instead of copying to new sheets
    The macro does not create any new sheets.

  41. #41
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi protonLeah,

    Thanks for your reply. Sorry (your macro does not create a new sheets, but a new sheets have to be created for the other files, for example, I have other 8 files, 4 ending with "m" and the other 4 ending "f"). What I need is to be able to use the combo box to update the two different sheets each time I import these files (sheet for the files ending with "m" and sheets for the files ending with "f"). So I need to have 2 sheets in my workbook for the imported data.

    Thanks for your reply and help, I really appreciate it.


    Many thanks

  42. #42
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Any ideas, help, please....

  43. #43
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,627

    Re: Using option buttons to import data from Notepad

    1. You must add a sheet for each of the additional files (8), naming them as on the last attachment.
    2. Add the four names (without the m & f) to sheet1
    3. Modify the combobox properties per the new attachment.
    Attached Files Attached Files

  44. #44
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi protonLeah,

    Thanks for your reply and help, I really appreciate it, and your attached workbook helped me a lot,so thanks again.

    Exactly that what I did (referring to your last post) I did add new sheets for each region and *** (m & f). But, what I hoping is that, instead of adding these new sheets, I want to have only two sheets on my workbook, and when I chose one the files in the combo box, goes directly to these two sheets (the one ending with "m", and the other "f").

    Thanks in advance,

  45. #45
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,627

    Re: Using option buttons to import data from Notepad

    In the previous macro, the line:

    Set MLT = thisWb.Sheets(FileToGet)

    selected a sheet tab based on the name of the imported file.

    Replace it with:

    Set MLT = thisWb.Sheets(Region)

    then the sheet tab will be selected by the m or f suffix.

  46. #46
    Forum Contributor
    Join Date
    01-25-2012
    Location
    CT
    MS-Off Ver
    Excel 2016
    Posts
    134

    Re: Using option buttons to import data from Notepad

    Hi ProtonLeah,
    I really appreciate your very helpful assistance. Thanks a lot. Its works fine now.

+ 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