Author: Oscar Cronquist Article last updated on January 02, 2018

A previous post described how to create a listbox filled with unique invoice numbers: Excel vba: Populate listbox with unique invoice numbers
This post describes how to view saved invoices.

Cancel Command button

  1. Press Alt-F11 to open visual basic editor
  2. Right click userform1
  3. Click "View Code"
  4. Copy and paste "Sub Button1_Click" code below into module
Private Sub CommandButton1_Click()
  Unload UserForm1
End Sub

"View Invoice data" Command button

Copy and paste "Sub Button1_Click" code below into module

Private Sub CommandButton2_Click()
Dim RowStart As LongDim RowEnd As Long

'Find invoice rows
RowStart = Sheets("Invoice data").Columns("A").Find(ListBox1.Value, _
SearchOrder:=xlRows, LookAt:=xlWhole, SearchDirection:=xlNext, _
RowEnd = Sheets("Invoice data").Columns("A").Find(ListBox1.Value, _
SearchOrder:=xlRows, LookAt:=xlWhole, SearchDirection:=xlPrevious, _  
LookIn:=xlValues).Row + 1
'Clear range

'Copy values
Sheets("Invoice").Range("B16").Resize(RowEnd - RowStart, 4).Value = _
Sheets("Invoice data").Range("D" & RowStart & ":G" & RowEnd).Value
Sheets("Invoice").Range("F3").Value = Sheets("Invoice data").Range("B" _
& RowStart).ValueSheets("Invoice").Range("D13").Value = _
Sheets("Invoice data").Range("A" & RowStart)
Sheets("Invoice").Range("B8").Value = Sheets("Invoice data").Range("C" _
& RowStart)
Unload UserForm1
End Sub

Previous blog posts:
Excel vba: Populate listbox with unique invoice numbers
Excel vba: Edit invoice data
Excel vba: Save invoice data
Invoice template with dependent drop down lists in excel

Download excel sample file for this tutorial.

Populate-invoice-listbox part 2.xls
(Excel 97-2003 Workbook *.xls)