Excel 2013 VBA Program With Code Examples
Excel 2013 VBA Program With Code Examples
for
Inventory Tracking
&
Auto Label printing
By
Alex Myers
Introduction:
The following document will give a brief explanation of the Workbook and it use. It will then
provide examples of the VBA (Visual Basic code for Applications) written in the back ground to automate
time stamps, cursor positioning, and label printing for the tracked inventory.
Workbook Description:
The following Excel workbook example is used to scan data from a tracking label on
manufactured inventory parts. Data such as Part Number, Serial Number, and Order Number. As each
part is scanned into the spreadsheet the log is then time stamped and the cursor is relocated to the next
line in the worksheet to begin scanning the next part into the log sheet.
The “Log Sheet” tab is the main tab created on this sheet and also has a couple of buttons
created to save the file to a specific file location and file name. The second button is a method to
remove a specific part from the inventory without losing the data as well as removing it from the
associated part label tabs that you can see in the screen shot. These tabs are located to the right of the
main “Log Sheet” tab.
At any rate this is my brief description and attempt at sharing this written Excel program. The following
screen shots are of the VBA code in the back ground and of the formulas used in specific cells of the
work sheets.
*VBA Code Screen – Red arrow indicates the worksheet that this code is written for.
VBA Code for “Log Sheet”:
'Time stamp program for Time stamps of each log sheet entry
'This part of the program also checks to see if the Part worksheet page is full through a cell
' value and calls the Printsheet function.
Dim rCell As Range
Dim rChange As Range
Dim Count1 As Integer
Dim increment As Integer
increment = 6
'Workbooks("QF_Cowl_Tracking_22819.xlsm").RefreshAll
ExitHandler:
Set rCell = Nothing
Set rChange = Nothing
Application.EnableEvents = True
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub
Dim Number
Dim PageNum
Number = 1
End Sub
***************************************************
*VBA Code for the main workbook as indicated by the red arrow above.
VBA Code:
Sub Save_File_Click()
MsgBox "File has been saved." & vbNewLine & "" & vbNewLine & "Please close Excel Window."
End Sub
*************************************************
Module #2 VBA Code:
Sub Shipping_button_Click()
Dim LSearchValue As String
'Dim c As String
Sub Save1()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="N:\Production\Bake Line QF-Cowel tracking\" & Worksheets("Log
sheet").Range("G2").Text & "_" & Worksheets("Log sheet").Range("G3").Text & ".xlsm", FileFormat:= _
xlOpenXMLWorkbookMacroEnabled, Password:=vbNullString, WriteResPassword:=vbNullString, _
ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True
Formulas:
Formula in the cells of column ‘A’ that searches the data on the “Log Sheet” tab and brings over the
serial number if the part number matches the part number given as the tab’s name.
{=IF(ISERROR(INDEX(DataARRAY,SMALL(IF(PartArray="17-20469-000",ROW(PartArray)-4),ROW('Log
Sheet'!1:1)),2)),"",INDEX(DataARRAY,SMALL(IF(PartArray="17-20469-000",ROW(PartArray)-4),ROW('Log
Sheet'!1:1)),2))}
Then the next formula on the worksheets is in column ‘B’ and this formula assist with the VBA code
written to automatically print out a shipping label if 6 of a particular part has been scanned.
=IF((LEN(A2) = 7),1,"")
This is again a brief written summary and description of my inventory tracking and label printing
program.
I hope you enjoyed this small document and it may have help you in learning VBA code for Applications.
Thank you,
Alex Myers