Results 1 to 4 of 4

User-defined function returning #ARG! error

Threaded View

  1. #1
    Registered User
    Join Date
    12-16-2013
    Location
    Warsaw
    MS-Off Ver
    Excel 2003
    Posts
    2

    User-defined function returning #ARG! error

    Hi,
    I want to create function in visual basic and use it in excel. I have function which counts EAN13. I create function by: Developer/Visual Basic - create new module and paste code. Save as .xlsm. When I write "=ean13(123456789012)" it's not working, because it's displayed "#ARG!" instead of correct value. What did I do wrong?

    This function:
    Public Function ean13$(chaine$)
      'Cette fonction est regie par la Licence Generale Publique Amoindrie GNU (GNU LGPL)
      'This function is governed by the GNU Lesser General Public License (GNU LGPL)
      'V 1.1.1
      'Parametres : une chaine de 12 chiffres
      'Parameters : a 12 digits length string
      'Retour : * une chaine qui, affichee avec la police EAN13.TTF, donne le code barre
      '         * une chaine vide si parametre fourni incorrect
      'Return : * a string which give the bar code when it is dispayed with EAN13.TTF font
      '         * an empty string if the supplied parameter is no good
      Dim i%, checksum%, first%, CodeBarre$, tableA As Boolean
      ean13$ = ""
      'Verifier qu'il y a 12 caracteres
      'Check for 12 characters
      If Len(chaine$) = 12 Then
        'Et que ce sont bien des chiffres
        'And they are really digits
        For i% = 1 To 12
          If Asc(Mid$(chaine$, i%, 1)) < 48 Or Asc(Mid$(chaine$, i%, 1)) > 57 Then
            i% = 0
            Exit For
          End If
        Next
        If i% = 13 Then
          'Calcul de la cle de controle
          'Calculation of the checksum
          For i% = 12 To 1 Step -2
            checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
          Next
          checksum% = checksum% * 3
          For i% = 11 To 1 Step -2
            checksum% = checksum% + Val(Mid$(chaine$, i%, 1))
          Next
          chaine$ = chaine$ & (10 - checksum% Mod 10) Mod 10
          'Le premier chiffre est pris tel quel, le deuxieme vient de la table A
          'The first digit is taken just as it is, the second one come from table A
          CodeBarre$ = Left$(chaine$, 1) & Chr$(65 + Val(Mid$(chaine$, 2, 1)))
          first% = Val(Left$(chaine$, 1))
          For i% = 3 To 7
            tableA = False
             Select Case i%
             Case 3
               Select Case first%
               Case 0 To 3
                 tableA = True
               End Select
             Case 4
               Select Case first%
               Case 0, 4, 7, 8
                 tableA = True
               End Select
             Case 5
               Select Case first%
               Case 0, 1, 4, 5, 9
                 tableA = True
               End Select
             Case 6
               Select Case first%
               Case 0, 2, 5, 6, 7
                 tableA = True
               End Select
             Case 7
               Select Case first%
               Case 0, 3, 6, 8, 9
                 tableA = True
               End Select
             End Select
           If tableA Then
             CodeBarre$ = CodeBarre$ & Chr$(65 + Val(Mid$(chaine$, i%, 1)))
           Else
             CodeBarre$ = CodeBarre$ & Chr$(75 + Val(Mid$(chaine$, i%, 1)))
           End If
         Next
          CodeBarre$ = CodeBarre$ & "*"   'Ajout separateur central / Add middle separator
          For i% = 8 To 13
            CodeBarre$ = CodeBarre$ & Chr$(97 + Val(Mid$(chaine$, i%, 1)))
          Next
          CodeBarre$ = CodeBarre$ & "+"   'Ajout de la marque de fin / Add end mark
          ean13$ = CodeBarre$
        End If
      End If
    End Function
    Moderator's note: Please review forum rules. Rule #1: Good thread titles. I have updated this title because it is your first post. --6SJ
    Last edited by 6StringJazzer; 12-16-2013 at 10:00 AM. Reason: title

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Improve this function and create a similar function
    By lesoies in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-01-2013, 08:23 AM
  2. [SOLVED] Create function with a function name as a variable
    By Yonni in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2012, 02:08 PM
  3. Average Function-how I would create an Avergae function?
    By Max_Current in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-07-2007, 04:21 PM
  4. [SOLVED] Macro Function:create a new function
    By Tomas in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 05-09-2006, 07:55 AM
  5. [SOLVED] How do I create a function into function list?
    By Hossein Farhani in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-23-2005, 02:07 PM

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