+ Reply to Thread
Results 1 to 17 of 17

Decrease serial number if matching file found

  1. #1
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Decrease serial number if matching file found

    Hi Everyone, Any help with any part of this issue would be a great help. I have posted this a couple of times before. You are probably getting sick of seeing this but I hoped someone may be able to help, I'm not giving up on this issue.
    http://www.excelforum.com/excel-prog...ml#post3530142

    So to the brain achingly annoying issue. What I'm trying to achieve is;
    1. When a new document is opened from my template a unique serial number (in format "00000") is generated (currently using txt file)
    2. Once the number is generated a search is preformed to see if a file exists saved with the same serial number as a name.
    3. If a file exists then the txt files stored value is decreased by 1 and that is displayed in "K5".
    4. If the search returns a 0 then the original serial number is displayed.

    Please Login or Register  to view this content.

    Currently i don't belive the search function is working. So any help with that would be greatly appreciated and oddly once the search fails to run properly the original serial number dissapears.

    Thanks Everyone.
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Decrease serial number if matching file found

    What are you using the 'search' function for?

    If you want to find out if a file exists why not just use Dir?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Re: Decrease serial number if matching file found

    Many thanks for getting back to me. I'm quite new to VBA and didn't know of Dir, but a brief read makes me think it would work well. Could you show me how to pass the contents of cell K5 to the Dir search?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Decrease serial number if matching file found

    What exactly does K5 have in it?

  5. #5
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Re: Decrease serial number if matching file found

    K5 is where the serial number is displayed. Which is generated by the "Function GetSerialNumber".

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Decrease serial number if matching file found

    I thought you were searching for a file.

  7. #7
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Re: Decrease serial number if matching file found

    Yes sorry to be so confussing. I am trying to search for a file, as discribed in my oringinal post.
    "1. When a new document is opened from my template a unique serial number (in format "00000") is generated (currently using txt file)
    2. Once the number is generated a search is preformed to see if a file exists with the same serial number as a name."
    So what I'm trying to do is, generate a serial number and then check that a file does exists already with that serial number. I am trying to make sure no one can VOID a number without meaning to.

  8. #8
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Re: Decrease serial number if matching file found

    The file will be stored in the same location as the template.

  9. #9
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Re: Decrease serial number if matching file found

    Hi Norie, I've been trying to work this out for myself and done a lot of reading and searching on the dir subject. However I just can't get it to work for me. Can you help?

    Please Login or Register  to view this content.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Decrease serial number if matching file found

    What's the name of the text file you are looking for and where is it located?

  11. #11
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Re: Decrease serial number if matching file found

    Sorry, its not a text file its a xls file, it would have the same name as a serial number eg "25601". It would be located in the same directory as the original template file C:\Documents and Setting\ect.xls. However if you mean the text file that stores the value that the serial number is generated from then that is called "Invoice.txt" and that again is in the same directory.

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Decrease serial number if matching file found

    If it is an xls file then the function you posted in post #9 should work.

    If it isn't how isn't it?

  13. #13
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Re: Decrease serial number if matching file found

    It suggests that the syntax has an error. It gives an "Compile Error. Exspected List Seperator or )" error message.

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Decrease serial number if matching file found

    There's a missing ".
    Please Login or Register  to view this content.
    By the way, what are you going to do if the file doesn't exist?

  15. #15
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Re: Decrease serial number if matching file found

    Thank you, how stupid of me. Well that is sort of working now. It seems to run and exectue however when I save an xls file with the same name as the next serial number to be generated it still says "File does not exist".
    What I have done is add a section to the search function to exectue the opposit of the generate serial number code so instead on +1 to the txt file its -1. However when the search function is preformed atm the contents of "K5" (serial number) is dissapears. Any ideas why this is happening?

  16. #16
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Re: Decrease serial number if matching file found

    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    10-07-2013
    Location
    Wilts, England
    MS-Off Ver
    Excel 2013
    Posts
    100

    Re: Decrease serial number if matching file found

    Just to clarify, it clears the content of cell K5 after the ok button is pushed on the MsgBox.

+ 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. Incrament serial number up or down using txt file and directory search
    By beenbee in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 01-29-2014, 08:38 AM
  2. Replies: 1
    Last Post: 02-21-2013, 05:49 PM
  3. Replies: 3
    Last Post: 09-18-2012, 01:01 AM
  4. Finding a serial number in a list of serial numbers
    By zocoloco in forum Excel General
    Replies: 2
    Last Post: 02-04-2009, 05:20 AM
  5. [SOLVED] automatic new serial number for each new sheet within one file
    By ahmed in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-26-2005, 10:06 AM

Tags for this Thread

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