0

I was tasked with trying to create a VBA Macro that will generate barcodes based on the values I have and also create a button that will print only the barcodes and not the values. I have found online some options to generate the barcodes but the format does not look correct as I also need the number on the bottom of the barcode. I'm a beginner at using VBA macro and I am not sure whether all of this is entirely possible?

This is a link to the current VBA I use to generate my barcodes:

https://code.adonline.id.au/easily-generate-code-128-barcodes-in-excel/

For example, this is what I currently have:

enter image description here

This is an example of what I would like my barcodes to be:

enter image description here

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Matthew
  • 5
  • 4

1 Answers1

0

You could do something like this:

Sub Tester()
    Dim c As Range, v As String, bc
    
    For Each c In Range("A1:A5").Cells    'values to create barcodes from
        v = c.Value                       'value to be barcoded
        bc = Code128(v)                   'using your linked function
        With c.Offset(0, 1)
            .Font.Size = 12               'reset font size
            .Font.Name = "Calibri"        'reset font
            .HorizontalAlignment = xlCenter
            .Value = bc & vbLf & v
            'format the barcode characters
            .Characters(1, Len(bc)).Font.Name = "Libre Barcode 128"
            .Characters(1, Len(bc)).Font.Size = 16
        End With
    Next c
End Sub

Output:

enter image description here

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Hi thanks for this, I am just wondering why my output is different to yours above? https://i.imgur.com/Xo91WnD.png – Matthew May 23 '22 at 23:52
  • Maybe your barcode font has a different name? What font are you using? – Tim Williams May 24 '22 at 00:00
  • I have updated the font to Code 128 which I downloaded from here: https://www.dafont.com/code-128.font and it's working now! Only issue is the format doesn't look as nice as yours as the barcode is smaller than the bottom numbers but I guess that's due to the font? https://i.imgur.com/XOXBvj0.png – Matthew May 24 '22 at 00:48
  • You can try adjusting the relative font sizes and see if that improves things. – Tim Williams May 24 '22 at 02:04