How to Generate Code 128 Barcode Font for Excel

Get FREE Advanced Excel Exercises with Solutions!

In this article, we will learn to generate code 128 barcode font for Excel. There are some methods to use code 128 barcode font in Excel, but most are challenging to apply and don’t work on all versions of Excel. Today, we will demonstrate a method to generate code 128 barcode font with easy steps in Excel. After reading the article, you will be able to use code 128 barcode font very easily. So, without any delay, let’s start the discussion now.

Note: The given VBA user-defined function Code128 can only be used in the Windows operating system. It will not work properly in Mac OS.

What Is Code 128 Barcode Font?

Code 128 is a modern and famous barcode font. Its popularity is increasing day by day because it is a high-density barcode font that supports alphanumeric characters.

Generally, code 128 consists of seven sections. They are:

  • Quiet Zone
  • Start Symbol
  • Encoded Data
  • Check Symbol
  • Stop Symbol
  • Final Bar
  • Quiet Zone

The code 128 barcode font has 3 subsets. They are described briefly below:

  • Code 128A: It supports ASCII without lowercase characters.
  • Code 128B: It supports ASCII without the initial special characters.
  • Code 128C: This subset supports Numeric Values.

To explain the steps, we will use a dataset that contains information about some products and their data. Using the method, we will try to generate barcodes with Code 128 font for the data of each product.


STEP 1: Downloading Code 128 Font

  • First of all, you need to download Code 128.
  • After that, extract the downloaded folder to the C:\Windows\Fonts folder.
  • Otherwise, unzip the downloaded folder, copy the Code 128 font and paste it to the C:\Windows\Fonts folder.
  • Also, select Continue if the administrator permissions window appears.

Step-by-Step Procedures to Generate Code 128 Barcode Font for Excel

Read More: How to Generate Barcode Numbers in Excel 


STEP 2: Using Excel VBA to Create User-Defined Function

  • Secondly, go to the Developer tab in the ribbon and select Visual Basic.
  • As a result, it will open the Visual Basic window.

Step-by-Step Procedures to Generate Code 128 Barcode Font for Excel

  • After that, select Insert and then Module in the Visual Basic window.
  • At this moment, the Module window will appear.

Step-by-Step Procedures to Generate Code 128 Barcode Font for Excel

  • Now, we need to type a code in the Module window.
  • You can copy it from below and paste it into the Module window:
Option Explicit
Public Function Code128(SourceString As String)
    Dim Counter As Integer
    Dim CheckSum As Long
    Dim mini As Integer
    Dim dummy As Integer
    Dim UseTableB As Boolean
    Dim Code128_Barcode As String
    If Len(SourceString) > 0 Then
        For Counter = 1 To Len(SourceString)
            Select Case Asc(Mid(SourceString, Counter, 1))
                Case 32 To 126, 203
                Case Else
                    MsgBox "Invalid character in barcode string" & vbCrLf & vbCrLf & "Please only use standard ASCII characters", vbCritical
                    Code128 = ""
                    Exit Function
            End Select
        Next
        Code128_Barcode = ""
        UseTableB = True
        Counter = 1
        Do While Counter <= Len(SourceString)
            If UseTableB Then
                mini = IIf(Counter = 1 Or Counter + 3 = Len(SourceString), 4, 6)
                GoSub testnum
                If mini% < 0 Then
                    If Counter = 1 Then
                        Code128_Barcode = Chr(205)
                    Else
                        Code128_Barcode = Code128_Barcode & Chr(199)
                    End If
                    UseTableB = False
                Else
                    If Counter = 1 Then Code128_Barcode = Chr(204)
                End If
            End If
            If Not UseTableB Then
                mini% = 2
                GoSub testnum
                If mini% < 0 Then
                    dummy% = Val(Mid(SourceString, Counter, 2))
                    dummy% = IIf(dummy% < 95, dummy% + 32, dummy% + 100)
                    Code128_Barcode = Code128_Barcode & Chr(dummy%)
                    Counter = Counter + 2
                Else
                    Code128_Barcode = Code128_Barcode & Chr(200)
                    UseTableB = True
                End If
            End If
            If UseTableB Then
                Code128_Barcode = Code128_Barcode & Mid(SourceString, Counter, 1)
                Counter = Counter + 1
            End If
        Loop
        For Counter = 1 To Len(Code128_Barcode)
            dummy% = Asc(Mid(Code128_Barcode, Counter, 1))
            dummy% = IIf(dummy% < 127, dummy% - 32, dummy% - 100)
            If Counter = 1 Then CheckSum& = dummy%
            CheckSum& = (CheckSum& + (Counter - 1) * dummy%) Mod 103
        Next
        CheckSum& = IIf(CheckSum& < 95, CheckSum& + 32, CheckSum& + 100)
        Code128_Barcode = Code128_Barcode & Chr(CheckSum&) & Chr$(206)
    End If
    Code128 = Code128_Barcode
    Exit Function
testnum:
        mini% = mini% - 1
        If Counter + mini% <= Len(SourceString) Then
            Do While mini% >= 0
                If Asc(Mid(SourceString, Counter + mini%, 1)) < 48 Or Asc(Mid(SourceString, Counter + mini%, 1)) > 57 Then Exit Do
            mini% = mini% - 1
            Loop
        End If
        Return
End Function

Step-by-Step Procedures to Generate Code 128 Barcode Font for Excel

VBA Code Explanation:

In this code, we will create a function that will convert a string to barcodes. Here, we will use the Code 128 font.

  • The input parameter is a string.
  • In the output, we will get a barcode in the Code 128 font if the string is valid.
  • Otherwise, it will display an empty string.
Public Function Code128(SourceString As String)

This part denotes the function name and it is Code128(). You need to insert the string inside the parentheses.

Dim Counter As Integer
Dim CheckSum As Long
Dim mini As Integer
Dim dummy As Integer
Dim UseTableB As Boolean
Dim Code128_Barcode As String

These are the variables that will be used in the code.

If Len(SourceString) > 0 Then
For Counter = 1 To Len(SourceString)
Select Case Asc(Mid(SourceString, Counter, 1))
Case 32 To 126, 203
Case Else
MsgBox "Invalid character in barcode string" & vbCrLf & vbCrLf & "Please only use standard ASCII characters", vbCritical
Code128 = ""
Exit Function
End Select
Next

In this section, the code will check for valid characters. If it finds no valid character, then, it will ask the user to use standard ASCII characters.

For Counter = 1 To Len(Code128_Barcode)
dummy% = Asc(Mid(Code128_Barcode, Counter, 1))
dummy% = IIf(dummy% < 127, dummy% - 32, dummy% - 100)
If Counter = 1 Then CheckSum& = dummy%
CheckSum& = (CheckSum& + (Counter - 1) * dummy%) Mod 103
Next

Here, this part calculates the value of the CheckSum variable.

CheckSum& = IIf(CheckSum& < 95, CheckSum& + 32, CheckSum& + 100)
Code128_Barcode = Code128_Barcode & Chr(CheckSum&) & Chr$(206)
End If

In this part, the code calculates the CheckSum ASCII code. After adding the ASCII code, it moves to the next part.

mini% = mini% - 1
If Counter + mini% <= Len(SourceString) Then
Do While mini% >= 0
If Asc(Mid(SourceString, Counter + mini%, 1)) < 48 Or Asc(Mid(SourceString, Counter + mini%, 1)) > 57 Then Exit Do
mini% = mini% - 1
Loop
End If

In the last part, the code will check for the numeric values inside the given string.

This VBA code was found from myonlinetraininghub.com.

  • After typing the code, press Ctrl + S to save it.
  • In the following step, close the Visual Basic window.

Read More: How to Use EAN 13 Barcode Generator in Excel


STEP 3: Using Code 128 Function

  • Thirdly, we need to use the function that we created by applying the VBA.
  • In order to do that, select Cell D5 and type the formula below:
=Code128(C5)

Step-by-Step Procedures to Generate Code 128 Barcode Font for Excel

Here, the function will convert the data of Cell C5 into a barcode.

  • In the following step, press Enter to see the result.

Step-by-Step Procedures to Generate Code 128 Barcode Font for Excel

Read More: How to Calculate Barcode Check Digit with Excel Formula


STEP 4: Changing Excel Theme Font and Size

  • In the fourth step, you need to change the font and size.
  • For that purpose, select Cell C5.
  • Then, go to the Home tab and select Code 128 in the font theme box.
  • Also, select 36 in the font size box.

Read More: How to Add Barcode Font in Excel 


STEP 5: Resizing Column Width and Row Height

  • After changing the font theme and size, we need to resize column width and row height.
  • In our case, we have set the width of Column D to 30 and the Row Height to 50.

STEP 6: Using Fill Handle to Copy the Formula

  • In the following step, select Cell D5 and drag the Fill Handle down to the rest of the cells.

Read More: How to Create Barcode Using 3 of 9 Font in Excel


Final Output of Code 128 Barcode Font for Excel

  • Finally, change the Row Height of Row 6,7,8, and 9 to 50.
  • After finishing all the steps, you will see results like the picture below.

Read More: How to Use Code 39 Barcode Font for Excel


Download Practice Book

You can download the practice book from here.


Conclusion

In this article, we have demonstrated step-by-step procedures to generate Code 128 Barcode Font for Excel. I hope this article will help you to create barcodes easily. Moreover, you can use the workbook to practice. In order to do so, download the workbook. We have added the workbook at the beginning of the article. Last of all, if you have any suggestions or queries, feel free to ask in the comment section below.


Related Articles

What is ExcelDemy?

ExcelDemy Learn Excel & Excel Solutions Center provides free Excel tutorials, free support , online Excel training and Excel consultancy services for Excel professionals and businesses. Feel free to contact us with your Excel problems.
Mursalin Ibne Salehin
Mursalin Ibne Salehin

Hi there! This is Mursalin. I am currently working as a Team Leader at ExcelDemy. I am always motivated to gather knowledge from different sources and find solutions to problems in easier ways. I manage and help the writers to develop quality content in Excel and VBA-related topics.

52 Comments
  1. Hi Martin,

    I’m looking at this as an ad-hoc solution for low-use barcodes. When comparing to current barcode examples, the start-tags do not appear correctly on my barcodes.

    Thanks,
    Dom

    • Hello, Dom!
      Thanks for your feedback. If you are facing any problems generating code 128 barcode font in Excel, then you can ask here. We will try to reply to you as soon as possible.
      Thanks!

      • Hello, thank you very much for your contribution, it is great. But is it possible to add a function so that when the same code is read twice, it throws me a message saying that it is duplicated?

        • Avatar photo
          Mashhura Jahan Jun 21, 2023 at 9:41 AM

          Hi OMAR DEL VALLE,
          Thanks for your comment. I am replying to you on behalf of ExcelDemy. You can apply the following formula for finding duplicate barcodes.

          =IF(COUNTIF($C$5:C5,C5)>1,"Duplicate",Code128(C5))

          But, here the duplicates are also in Code 128 font to change that follow these steps.
          • Right-click on the sheet name >> select View Code.

          • Write the following code.

          Private Sub Worksheet_SelectionChange(ByVal Target As Range)
          For row_no = 1 To 100
              If Range("D5").Cells(row_no, 1).Value = "Duplicate" Then
                  Range("D5").Cells(row_no, 1).Font.Name = "Calibri"
                  Range("D5").Cells(row_no, 1).Font.Size = 11
              End If
          Next
          End Sub

          • Now, just drag the Fill Handle and you will get your desired result.

          I hope this will help you to solve your problem. Please let us know if you have other queries.
          Regards
          Mashhura Jahan
          ExcelDemy.

  2. Hello. I’m attempting to create a barcode that also include the numeric 0. 02628107336750 as an example. How can I use this article to achieve this result.

    • Dear CHRIS,
      Thanks for your comment. Excel omits the leading zero by default. So, it’s not possible to get the desired barcode.
      • To solve this, you must add an apostrophe (‘) in front of the leading zero.
      • So, select Cell C5 in the VBA sheet of the workbook.
      • Type ‘02628107336750 in Cell C5.
      • Press Enter.
      • You will get your results in Cell D5.
      I hope this will help you to solve your problem.
      Thanks.

  3. I am using your VB code to generate the following barcode output – Õ46G4YŒ
    However the Õ and the Œ, at the beginning and the end do not change into barcodes when the code128 font is applied, they stay as alphanumberic characters. What am I doing wrong?

    • Dear NEIL,
      Thanks for your comment. Code 128 barcode font has 106 unique representations and supports standard ASCII characters. Unfortunately, Õ and Œ – these two characters are not supported by code 128 barcode font. But you can try other barcode fonts to solve this issue. You can use the free online barcode generator for that purpose. I hope this will help you to solve your problem.
      Thanks.

  4. Hello!
    How can I generate the barcode with the ASCII characters below the barcode on same cell.
    Thanks

    • Hello CRISNA,
      Thanks for your comment. You can’t generate the text below the barcode with the code 128 font we used here. But you can use the Libre Barcode 128 Text font for that. Also, you can follow this article https://www.exceldemy.com/generate-barcode-numbers-in-excel/ to generate characters below the barcode. I hope this will help you to solve your problem. Please let us know your queries if you face any issues.
      Thanks.

  5. Hello,
    I’m hoping to insert a Horizontal Tab in between two strings using your method, “XXXX.1TAB123456” with the intent of using one barcode to enter two separate fields
    Is there a special character or function to be implemented to do this? Or is it even possible?
    Thank you!

    • Dear MICHAEL,
      Thanks for your comment. You can insert a Tab using “~009” inside the string. For example, XXXX.1TAB123456 can be written as XXXX.1~009123456. But unfortunately, it will not show two separate fields in one barcode. From my understanding, you need to use other barcode fonts for that purpose.
      Otherwise, you can look at the solution below. But this solution will not provide you with one barcode. Here, we tried to concatenate two separate barcodes in one cell. Here, we will use the dataset below.

      Let’s follow the steps below for the solution.
      ● Firstly, change the fields into barcode strings.
      ● To do so, select Cell D5 and type the formula below:
      =Code128(B5)

      ● Also, do the same for the second field.

      ● After that, select Cell B7 and type the formula below:
      =CONCAT(D5,CHAR(9),E5)

      ● Hit Enter to see the result.

      ● Now, select Cell B7 again and change the font theme to Code 128.
      ● Also, adjust the font size.

      ● Finally, you will get results like the picture below.

      I hope this solution will help benefit you to some extent. Please let us know if you face any other issues.
      Thanks!

  6. Is there similar VBA code for Microsoft Word? Trying to get this font(code 128) to work with a mail merge.

  7. Hi RICK,

    Thanks for your comment. Unfortunately, there is no similar VBA code for Microsoft Word. You need to use the VBA in Excel to get the barcode using Code 128. But you can follow the link below to use code 128 barcode font in Microsoft Word.
    https://www.exceldemy.com/print-barcode-labels-in-excel/#Step_4_Generating_and_Printing_Barcode_Labels

    I hope this will help you to solve your problem. Please let us know if you face any other issues.
    Thanks!

  8. When I’m trying to convert numbers to barcode im getting errors. For example number 192697
    gives Í3:ĹWÎ where Ĺ is not barcode, the same is with 194898 which gives output Í3PĆĘÎ – when font changed to code128 it still shows ĆĘ in middle. How can I solve that – there must be some error in VBA…

    • Hi DAWID,

      Thanks for your comment. Sorry to hear that you are not getting the desired output. I have tried to convert 192697 and 194898 to barcodes using the same code. In my case, it worked. You can see the result below:

      I am also attaching the Excel file below:
      Answer.xlsm
      Moreover, the VBA code is not error-free. It can introduce errors sometimes. You can copy the code and paste it into a new workbook. It may help you to get the desired results.
      I hope this will help you to solve your problem. Please let us know if you have other queries.
      Thanks!

  9. Hello. Thank you for posting this. I have folowed the procedure and it doesnt generate the desired readable barcode. It creates the correct text: ÌA00M2Ç@A8Î
    but when the font is changed to code 128 it creates a barcode that is not scannable.

    Any thoughts?

    • Hi KIERAN,

      Thanks for your comment. This is Mursalin from Exceldemy. I am not quite sure why you are getting a barcode that is not scannable. Because in my case, after changing the text to Code 128, I am getting the desired scannable barcode.

      It will be helpful for me if you provide the Excel file or an image in the comment section. Or you can send the Excel file to [email protected]. I hope I can give a solution after watching the file.
      Thanks!

  10. This was not very helpful for people like me who do not have the Developer tab on their menu in Excel. I don’t understand why my characters for the barcode is %P+999-807989$ and when I change the font setting on that field to code 128, the barcode scanner cannot read it.

    • Hi FREEJOJOEY,

      Sorry to hear about your problem. I am replying to you on behalf of Exceldemy. The Developer tab is not included in the ribbon by default. But you can easily add it. To add the Developer tab, please the steps of the link below:
      Get Developer Tab
      After inserting the Developer tab, follow the steps of the article. If you follow the steps correctly, you will get the scannable barcodes. You must insert the VBA using the Developer tab as stated in STEP 2 for getting the correct characters.

      Thanks!

  11. I’m on MAC and just opening up your example if I click on the cell and then off changes the bar code.

    Note the << and the CE below. This is on your data first row. A00M23233.

    ÃA00M2«@A8Œ

    Does this have to do with MAC UF8? Anyway to fix it?

  12. Hi Casey,
    You may not get the desired output if you download the excel file attached to this article and perform operations.

    1. You must download the barcode font. The link is in the 1st step of this article
    2. Also, code 128 has 106 distinct characters. Πis not available in code 128.
    Maybe these are the 2 issues that need to be resolved.
    However, if these don’t satisfy you, please let us know.
    Have a great day!

  13. What a cool bit of code! It’s working fine so far and it was truly free.
    I’m using code 128 in Excel. It’s pretty simple for the SKU’s we are working with.
    Thank you So Much!
    I’ll reply back if I find an issue and will bookmark this page to check for updates.

    • Hi MYLES,

      Thanks for your comment. We are very glad to know that we could be of help to you. Let us know if you have any queries.

      Good luck.

  14. Hi Mursalin. Becasue i have problem with formula while im generating code128 characters i download also workbook from your entry Oct 10, 2022 at 4:31 PM. Problem is also there. For meny antry im receiving not recognizing characters in barcode. You can try for example 456987321596328 Go you have any idea how to solve it?

    • Hi Jacek,
      Thank you for sharing your query. To solve this, you can try another formula instead after copying the Code 128 Font in the C:\Windows\Fonts folder.
      First, insert this formula for the data 456987321596328 and press Enter.
      ="*"&B5&"*"

      Then, change the Font to Code 128 and the Size to 36 for creating the barcode.

      Make sure, your input data is in Text format before applying the formula.
      Moreover, VBA is not error-free. So I suggest you create a new Excel-Macro Enabled Workbook and copy-paste the VBA code to create your own barcode.
      I hope this will help you to solve your problem. Please let us know if you have other queries.
      Thanks!

  15. Is it possible to encode keyboard functions into barcode such as “TAB” and “Return” key?

    • Hello, CL.
      Of course, it’s possible to solve your mentioned problem!
      You will need to get the ASCII code of the respective keys. Now, open a new Excel file and follow all the steps written in this article, i.e. downloading Barcode fonts 128, installing them, creating a UDF, and the next steps. Now insert the ASCII codes of the respective keys and you will get your desired Barcode. See what we have got.
      Keyboard keys to Barcode
      So, what you need to do yourself, just finding the ASCII codes! What else to do are already mentioned in this article.

      Note: You may need to open a new file because as per the new update of Excel, a VBA code will be disabled in a downloaded xlsm file. Or you can solve the problem following this way.

  16. Hi Mursalin

    very detailed steps.

    Thanks!

    Peter

  17. Is there anyway to make this work for new excel files, or do you have to go through these steps and add the VB macro to any excel file that you wish to had 128 barcodes too?

    Thanks

    • Thank you, Rob, for your comment. To make the function available all the time, you can copy the code and paste the VBA code in a workbook. Then, save that workbook as Excel Add-in (*.xlam) file. Then, you will need to enable this add-in for a new Excel file. Thus, the function will be available as long as the add-in is enabled. Additionally, you will need to install the font beforehand.

      Let’s assume, you have exported the Excel file as “code 128.xlam” file. Then, you will need to enable this (File > Options > Add-ins > select Go).

      Then, you will need to enable the exported file name (in our case it is “code 128) and press OK.

      After doing this, whenever you create a new Excel file, you will be able to use this “CODE128()” function without copying the VBA code.

  18. Hello, if I get the table, which says “Ambiguous name detected: Code128” after inserting the =Code128(C5), what should I do? Or what I did wrong?

    • Reply Avatar photo
      Mursalin Ibne Salehin May 11, 2023 at 11:55 AM

      Hi INGRIDA,
      Thanks for your comment. Generally, the “Ambiguous name detected: Code128” error occurs when you insert the same formula in multiple Modules in Excel. In the picture below, you can see Module 1 and Module 2 contain the same code.

      In this case, you will get the “Ambiguous name detected: Code128” error.
      To solve it, you need to keep one module and remove others. To do so, right-click on the module you want to remove. Then, select Remove Module2.

      After that, select No from the pop-up message box.

      After that, you can apply the “=Code128” formula without any error. I hope this will help you to solve your problem. Please let us know if you have any other queries.

      Regards
      Mursalin,
      ExcelDemy.

  19. Hello,

    I am attempting to create a barcode with the enter function within the barcode.
    For example,

    ID: 833
    Password: 833

    I want to be able to scan the barcode and it input 833 \enter 833 \enter

    I was trying to follow the reply above by ALOK in November:
    “Hello, CL.
    Of course, it’s possible to solve your mentioned problem!
    You will need to get the ASCII code of the respective keys. Now, open a new Excel file and follow all the steps written in this article, i.e. downloading Barcode fonts 128, installing them, creating a UDF, and the next steps. Now insert the ASCII codes of the respective keys and you will get your desired Barcode. See what we have got.
    Keyboard keys to Barcode
    So, what you need to do yourself, just finding the ASCII codes! What else to do are already mentioned in this article.

    Note: You may need to open a new file because as per the new update of Excel, a VBA code will be disabled in a downloaded xlsm file. Or you can solve the problem following this way.”

    I don’t quite understand how they just used 9 and 10 for tab and enter respectively. I have the code working now – I am just troubled with the enter implementation.

    • Hello CALEB,

      Greetings! We appreciate you contacting us and commenting on our Excel blog post with your query. We appreciate your interest and are available to help. Enter the following VBA code in your module and correct the range in that code. Hopefully, this will implement the “Enter” function key in Excel which means the code will activate the next blank cell.

      Sub ActivateFirstBlankCell()
          Dim cell As Range
          ' Loop through each cell in the range D5:D11
          For Each cell In Range("D5:D11")
              ' Check if the cell is blank
              If cell.Value = "" Then
                  ' Activate the blank cell
                  cell.Activate
                  Exit Sub ' Exit the loop once the first blank cell is found
              End If
          Next cell
      End Sub

      The result will be like this.

      If you enter =CHAR(13) in cell A1 and =CODE128(A1) in cell B1 in Excel, the following will happen:

      1. Enter will be represented in cell A1 and will display a carriage return character, but it will not be visibly represented. A carriage return is a non-printable control character that represents a line break or the “Enter” key.
      2. In cell B1, the formula =CODE128(A1) will attempt to encode the content of cell A1 as a Code 128 barcode. However, since the content of cell A1 is a non-printable character (carriage return), it may not be directly interpretable by the CODE128 function. The CODE128 function is typically designed to encode printable ASCII characters.

      I’ll be pleased to help you further if you can give me more information or a sample of your Excel sheet if the issue continues.

      Regards

      Al Ikram Amit

      Team ExcelDemy

  20. Hello,
    I was trying to follow the response by ALOK Nov 13, 2022 at 12:04 PM
    I am using the code provided and it produces the barcode that can be read; however, I don’t understand how 9 and 10 mean tab and enter respectively. Can you provide me with an example piece of a cell that would return “8233 CR 8233 CR” in one barcode?

    • Hello, CALEB HOGUE. Thank you for your query. I understand you find difficulties using 9 and 10  as Tab and Enter. Please follow the below code to get 9 and 10 as Tab and Enter respectively.

      Sub ActivateFirstBlankCell()
      Dim cell As Range

      Sub ActivateFirstBlankCell()
          Dim cell As Range
      
          ' Loop through each cell in the range A1:A5
          For Each cell In Range("A1:A5")
              ' Check if the cell is blank
              If cell.Value = "" Then
                  ' Activate the blank cell
                  cell.Activate
                  Exit Sub ' Exit the loop once the first blank cell is found
              End If
          Next cell
      End Sub

      Also, follow the code that is already used in this article to convert “8233 CR 8233 CR” into one barcode

       

  21. Thank you for taking the time to create the code and instructions on how to make the barcode. I am encountering a problem that I hope you can help me with. My generated barcode does not work and does not match the master barcode 100%. Is there any chance you might know what I am doing wrong? Thank you again for your time!! If there is a way I can paste a copy of the master barcode that is working and the one that I am generating it may help

    • Hello, KENNY H.
      Thank you for sharing your problem with us. However, we would have liked more information about your problem. The method described in this article should work perfectly. Try to follow the methods and steps given in this article as it is. Make sure to download the proper code 128 font.
      You can email us screenshots of your problem or your workbook at [email protected]
      That would really help us to understand your problem and give a proper solution.
      You can also follow the articles below for generating barcodes in Excel.
      1. Create Barcode in Excel
      2. Generate 2D Barcode in Excel
      Have a nice day!
      Regards,
      Sourav
      Exceldemy.

  22. Thank you for the quick reply!! I tried sending an email to the address [email protected] but the email was returned saying the address was not good

  23. Thank you for this tutorial. I am having difficulty with the VBA function which does not seem to translate the data correctly.

    Your example, above, shows the following result in cell D5: ÌA00M2Ç@A8Î
    If I type this in manually, and convert the font to Code 128 the barcode is correct and readable, so my barcode font is OK.

    However, for me, the Code128 function in cell D5 returns: ÃA00M2«@A8Œ
    which gives the wrong barcode. In fact, two of the characters don’t give a barcode at all: « and Œ

    I’m running Excel v16 on MacOS 12.

    Thanks.

  24. Thank you for this article. I have a similar problem as mentioned by Casey, above, trying to use this on Excel for MacOS. The problem stems from the fact that the ANSI character set for Mac and PC are not the same.

    See for example:
    PC: https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/character-set-128255
    Mac: https://www.spreadsheetweb.com/mac-os-character-set/

    This creates a problem for all the VBA steps involving CHR(). I partly fixed this issue by substituting:
    Chr(235) instead of Chr(206) Î
    Chr(234) instead of Chr(205) Í
    Chr(130) instead of Chr(199) Ç
    Chr(237) instead of Chr(204) Ç
    Chr(233) instead of Chr(200) È

    This fixes the issue with the start/stop characters. However there is still a problem with the checksum that I can’t figure out. It still translates to the wrong character, and therefore the barcode can’t be read.

    • Thank you, MATTHEW, for bringing this issue to our attention. After examining the problem, we’ve also identified that the VBA function is not accurately translating the data on Mac OS. You have rightly indicated that the discrepancy in ANSI character codes between Windows and Mac operating systems is the root cause of this problem. We also found that certain characters, such as the initial and final characters Ì and Î, have different codes on Mac and Windows systems. We’re actively working on creating a new VBA function that will function correctly on Mac too.

      Regards
      Aniruddah
      Team Exceldemy

  25. Thanks for all the support and wonderful article, i want to use “-” in my barcode can you please help. like the code “30001-WK-H-0001”.

    • Reply Avatar photo
      Bishawajit Chakraborty Sep 18, 2023 at 4:05 PM

      Thank you, DAWOOD, for your wonderful question.

      In Excel, you can use a barcode font to create barcodes that include hyphens (“-“). Here are the steps to do it:

      1. Download and Install a Barcode Font:

      • First, you’ll need to download and install a barcode font that supports hyphens. You can find various barcode fonts online, and some popular ones include Code 128, Code 39, or EAN-13. Download the font and install it on your computer following the font installation instructions for your operating system.

      2. Enter Your Barcode Data:

      • In an Excel cell, enter your barcode data, including the hyphens.
      • Select all the codes in the cell.
      • From the Font group in the Home tab, choose Code 128 font format.
      • Press Enter.

      • Now, you will see the following result.

      I hope this may solve your issue. Also, please follow this article to get your answer with detailed explanations.

      That’s it! You’ve created a barcode in Excel with hyphens included in the data. Remember that the actual appearance and functionality of the barcode depend on the specific barcode font you’re using, so make sure to choose a font that supports the format you need.

      Bishawajit, on behalf of ExcelDemy

  26. Hi and thank you for you article, it has been really instructive!

    I have a problem, I’m trying to add to my SSCC Code the FNC-1 Character, but the font I have downloaded (the one you’ve posted above), doesn’t read this charachter, leaving me with a blank cell.

    Moreover, above, you are talking about using the =Code128b function for FCN-1 character adding purposes, but this function does not exists.

    Can you please help me?

    • Hello Stefano,
      I’m glad you found the information helpful, but I understand you’re still encountering issues with adding the FNC-1 character to your SSCC Code using a Code 128 font.

      I apologize for any confusion. The downloaded font here can not directly convert codes into Barcodes. You need to apply the VBA code to create the function “=Code128” to transform the SSCC code into symbols. After that, using the downloaded font will work.

      For your second problem, there isn’t a built-in Excel function called “=Code128b” for adding the FNC-1 character. Excel has no native function for generating Code 128 barcodes with special characters.
      That is why we built a function named “=Code128” using the VBA code for your convenience. Follow step 2 which is Using VBA to Create User Defined Function to create the function.
      I hope the confusion is cleared and this process willwork for you now.
      Regards
      Exceldemy Team

  27. Hello I am having trouble as the vba wont run on my other computer and I cannot figure out why… can you please help? has anyone else encountered a similar issue?

  28. Reply Avatar photo
    Musiha Mahfuza Mukta Nov 15, 2023 at 12:24 PM

    Hello Daphne, the VBA code is perfectly working on my laptop. The code is fine. To run a VBA code you must follow:
    1. Save your Excel file in .xlsm format
    2. Use the Excel offline version
    3. Enable macro content, to do so right click on Excel file >> from the Context Menu Bar >> go to Properties option >> General >> Security >> Unblock
    Still, if you face the problem, then please go through this article [Fixed!] Macros Not Working in Excel. Hopefully, this article will help you to solve your issue.
    Regards
    Exceldemy Team

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo