+ Reply to Thread
Results 1 to 20 of 20

How delete last item for file name using inputbox

  1. #1
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    How delete last item for file name using inputbox

    Hi,
    I would delete last item is existed in file name specific in folders and sub folders in this device
    C:\Users\OMMR\Desktop\DEL


    here is some files names
    C:\Users\OMMR\Desktop\DEL\ abfgtt6666-00 accrrt.xlsm
    C:\Users\OMMR\Desktop\DEL\out\nhjyyuuu12000 redffg yu7888.xls
    C:\Users\OMMR\Desktop\DEL\out\files\nbhjh 20000asd hjyu777 ghjytt.pdf

    so what I want to show input box to write file name when click ok then delete last item , if click cancel don't delete.
    example : show inputbox and write abfgtt6666-00 accrrt when click ok will become abfgtt6666-00 like this within device C:\Users\OMMR\Desktop\DEL\abfgtt6666-00
    the last item will be part alone by contains space before it.
    thanks

  2. #2
    Forum Contributor
    Join Date
    01-25-2025
    Location
    Presov, Slovakia
    MS-Off Ver
    2021
    Posts
    284

    Re: How delete last item for file name using inputbox

    Hi,
    just to be sure.
    Should it work like this?:
    1. I call the inputbox,
    2. I enter the text string ("abfgtt6666-00 accrrt") - without the extension,
    3. after confirming "yes", the program will search for a file that starts with the text from the input box.
    4. The program will change the file name so that it keeps the first part of the text:
    - abfgtt6666-00 accrrt.xlsm => abfgtt6666-00.xlsm
    - nhjyyuuu12000 redffg yu7888.xls => nhjyyuuu12000 redffg.xls
    - nbhjh 20000asd hjyu777 ghjytt.pdf => nbhjh 20000asd hjyu777.pdf

    Is that right?
    Question: - how do I know what the last part is? For example. "nhjyyuuu12000 redffg yu7888.xls" ?
    Question: - can there be more files with the same name. In a different directory, or with a different extension?

    m.s.

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,346

    Re: How delete last item for file name using inputbox

    Try it like this: I'm not sure what you want to do with the string once the last "word" is removed....


    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  4. #4
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    Re: How delete last item for file name using inputbox

    Is that right?
    yes
    Question: - how do I know what the last part is? For example. "nhjyyuuu12000 redffg yu7888.xls" ?
    I have no idea how specify last item. I suppose function could do that like Len.
    Question: - can there be more files with the same name. In a different directory, or with a different extension?
    yes , sorry I don't mentioned that.

  5. #5
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    Re: How delete last item for file name using inputbox

    Try it like this: I'm not sure what you want to do with the string once the last "word" is removed....
    I will check it .

  6. #6
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    Re: How delete last item for file name using inputbox

    @Bernie Deitrick
    doesn't delete anything when I go to directory!

  7. #7
    Forum Contributor
    Join Date
    01-25-2025
    Location
    Presov, Slovakia
    MS-Off Ver
    2021
    Posts
    284

    Re: How delete last item for file name using inputbox

    Hi Omar M,
    press "Start"
    m.s.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    Re: How delete last item for file name using inputbox

    press "Start"
    not really how works?!
    I wrote into inputbox asdff4 jk788 iiio yu777 and show me without change !
    doesn't delete anything !

  9. #9
    Forum Contributor
    Join Date
    01-25-2025
    Location
    Presov, Slovakia
    MS-Off Ver
    2021
    Posts
    284

    Re: How delete last item for file name using inputbox

    corrected
    m.s.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    Re: How delete last item for file name using inputbox

    great!
    just I would fix problem for duplicate same files names . I would delete one by one by show inputbox every time when there are many duplicates same files name in many folders .
    if I click cancel then don't delete and show inputbox again to delete same file name fro another folder.
    look if I have file name like this arrrrb ghhhhh hhhhh
    and arrrrb ghhhhh hhhhh is existed in different location in folders , when show inputbox and write arrrrb ghhhhh hhhhh and click cancel
    then will skip arrrrb ghhhhh hhhhh is existed in first folder and keep inputbox contains arrrrb ghhhhh hhhhh and move to second folder and when click ok then delete it and move third folder to delete it when click ok .

  11. #11
    Forum Contributor
    Join Date
    01-25-2025
    Location
    Presov, Slovakia
    MS-Off Ver
    2021
    Posts
    284

    Re: How delete last item for file name using inputbox

    Hi Omar M,
    deleting duplicate files is added. I just modified the method a bit:
    - you will see "Userform1",
    - in "Listbox1" there is a list of directories and files, in the order in which the program searches for them,
    - in "Listbox2" there is a list of renamed files
    --- if there are files with the same name but different extensions, they are separated by an empty line,
    --- files to be deleted have an "X" at the beginning of the line,
    --- by clicking on the given line, the "X" changes to "" (the file is not deleted),
    --- by clicking again, the "X" is reset,
    - marked files are deleted only after pressing the "Deleting marked files!" button

    I tested several options, but I might have overlooked something - so test.
    m.s.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    Re: How delete last item for file name using inputbox

    when select duplicates file from listbox1 will delete for all of duplicates !
    I suppose delete just selected item from listbox1 , right?
    Last edited by Omar M; 07-02-2025 at 02:01 PM.

  13. #13
    Forum Contributor
    Join Date
    01-25-2025
    Location
    Presov, Slovakia
    MS-Off Ver
    2021
    Posts
    284

    Re: How delete last item for file name using inputbox

    files marked with an "X" will be physically removed from the disk.
    m.s.delete last item v4.jpg

  14. #14
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    Re: How delete last item for file name using inputbox

    should delete last item for duplicates files , not delete file when select one of them!
    should keep the duplicates files .

  15. #15
    Forum Contributor
    Join Date
    01-25-2025
    Location
    Presov, Slovakia
    MS-Off Ver
    2021
    Posts
    284

    Re: How delete last item for file name using inputbox

    but in #10 you write about "removal".

  16. #16
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    Re: How delete last item for file name using inputbox

    sorry I don't clarify so !
    should delete item , not file.

  17. #17
    Forum Contributor
    Join Date
    01-25-2025
    Location
    Presov, Slovakia
    MS-Off Ver
    2021
    Posts
    284

    Re: How delete last item for file name using inputbox

    we can continue by:
    - entering the file name "xxxx yyy" in the "Inputbox",
    - a list of files with the same name "xxxx yyy" will be displayed in "Listbox2",
    - clicking on a line in "Listbox2" will mark the files to be renamed ("X"),
    - clicking on the button will rename the marked files (the last part "yyy" will be removed from them)
    Do you agree?

  18. #18
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    Re: How delete last item for file name using inputbox

    - clicking on the button will rename the marked files (the last part "yyy" will be removed from them)
    this is not clear for me !
    should remove last part for the selected item in listbox2, not delete all of them at once , because I need keep the others
    do you understand me what I would or...?

  19. #19
    Forum Contributor
    Join Date
    01-25-2025
    Location
    Presov, Slovakia
    MS-Off Ver
    2021
    Posts
    284

    Re: How delete last item for file name using inputbox

    - you enter text in the "Inputbox",
    - a list of found files ("Listbox2") will appear,
    - click on the lines where you want to remove the last part of the file name (X),
    - click on the "Renaming marked files!" button,
    - the code will modify the name of only the marked files.
    m.s.
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    06-07-2023
    Location
    Libya
    MS-Off Ver
    office 2019
    Posts
    94

    Re: How delete last item for file name using inputbox

    awesome work!
    thank you so much.

+ 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. Error message when inputbox entry does not match UF listbox item
    By Retroshift in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-11-2022, 12:34 PM
  2. Replies: 0
    Last Post: 01-29-2022, 05:37 AM
  3. [SOLVED] Adding delete code on userform to delete a row on sheet by selecting item on a listbox
    By darbar76528 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-07-2020, 12:50 PM
  4. Find available item from an Inventory file, searcg alternative Item if not avail
    By Oscar_Italy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2017, 08:34 AM
  5. [SOLVED] Opening file with a macro - Pick file [week] with inputbox
    By VitoBdG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-17-2015, 08:41 AM
  6. [SOLVED] Open excel file by providing a part of file name through inputbox
    By sbabu16 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-12-2014, 05:30 AM
  7. Delete Rows Using Inputbox
    By japorms in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-08-2008, 05:16 PM

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