Ah great. Thanks! It works perfectly now.
I have another question:
I am trying to create radio buttons that control whether the double click event is capable of occurring. I've created the radio button code:
Public Sub SetOptionButtonStates()
Dim PAL_Create As Boolean
Dim PO_Create As Boolean
PAL_Create = False
PO_Create = False
End Sub
Sub OptionButton3_Click()
PO_Create = True
PAL_Create = False
End Sub
Sub OptionButton5_Click()
PAL_Create = True
PO_Create = False
End Sub
And I have nested an If statement in the beforedoubleclick event sub:
Public Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Override the default double-click behavior with this function.
Cancel = False
'Declare variables.
Dim wks As Worksheet, xRow As Long
'If an error occurs, use inline error handling.
On Error Resume Next
'Capture double-clicked cell
Target.Select
'Capture double-clicked row
seRow = Target.Row
seCol = 0
'Insert in Row 15 of Sheet4
'xRow = Sheet4.Cells(Sheet4.Rows.Count, 1).End(xlUp).Row + 1
'For first product added to purchase order
If PO_Create = True Then
If Sheet4.Range("VendorName") = "" Then
xRow = 15
Sheet4.Cells(22, 6) = Cells(seRow, seCol + 5)
Sheet4.Cells(xRow, 3) = Cells(seRow, seCol + 2)
Sheet4.Cells(xRow, 9) = Cells(seRow, seCol + 6)
Sheet4.Cells(xRow, 10) = Cells(seRow, seCol + 9)
Sheet4.Cells(xRow, 1) = Cells(seRow, seCol + 7)
Sheet4.Cells(xRow, 2) = Cells(seRow, seCol + 8)
MsgBox "New Order Started: Producted Added to PO"
'If trying to add another product to purchase order, check to make sure the vendor is the same
Else
If Sheet4.Range("VendorName") = Cells(seRow, seCol + 5) Then
Dim i As Integer
For i = 16 To Sheet4.Range("Shipping").Row
If WorksheetFunction.Trim(Sheet4.Cells(i, 1).Value) = "" Then
xRow = i
Exit For
End If
Next i
If i = Sheet4.Range("Shipping").Row Then
Sheet4.Rows(Sheet4.Range("Shipping").Row - 1).EntireRow.Copy
Sheet4.Rows(Sheet4.Range("Shipping").Row).Insert Shift:=xlDown
Application.CutCopyMode = False
End If
Sheet4.Cells(xRow, 3) = Cells(seRow, seCol + 2)
Sheet4.Cells(xRow, 9) = Cells(seRow, seCol + 6)
Sheet4.Cells(xRow, 10) = Cells(seRow, seCol + 9)
Sheet4.Cells(xRow, 1) = Cells(seRow, seCol + 7)
Sheet4.Cells(xRow, 2) = Cells(seRow, seCol + 8)
MsgBox "Product Added to PO"
Else
MsgBox "This item is not from the same vendor"
End If
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub
But now the feature of adding a product by double-clicking doesn't work. I can't figure this out...
Bookmarks