Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
All I am wanting to do is if the item information is not found in the spreadsheet add it to the next available line but if it is found, locate the address and add the missing items by offsetting it from the location address. The error occurs on the code below and I have included all the code that has to do with rngItem. I know that if it doesn't find the item then there won't be any address assigned to it.
Thank You
Code:
Set rngItem = Range(rngItem.Address)
Code:
Option Explicit
Public lDz As Long, lCs As Long, ws_Count As Long, i As Long
Public sUOM As String, sPrdCde As String, formTitle As String
Public rngItem As Range
Sub Test()
Dim finalRow As Long, X As Long
Dim Rng As Range
lDz = 0
lCs = 0
sUOM = ""
With ActiveWorkbook.Worksheets(formTitle)
Set Rng = .Range("B2", .Range("B" & Rows.Count).End(xlUp))
End With
Set rngItem = findItem(Rng, sPrdCde)
If Not rngItem Is Nothing Then
lDz = Val(Range(rngItem.Address).Offset(, 2))
lCs = Val(Range(rngItem.Address).Offset(, 3))
sUOM = Range(rngItem.Address).Offset(, 4)
End If
If lDz = 0 Or lCs = 0 Or sUOM = "" Then
Call ErrorTrap
End If
End Sub
Code:
Option Explicit
Public sUOM As String
Private Sub cmdbtnAddItem_Click()
Dim LastRow As Long
Dim cnt As Integer
Dim ctl As Control
Worksheets(Chattemfrm.cmbSDPFLine.Value).Select
LastRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
Set rngItem = Range(rngItem.Address)
If rngItem.Offset(, -1).Value = "" Then
Cells(LastRow, 1).Value = Len(Me.txtbxDescription.Value)
Else
rngItem.Offset(, -1).Value = Len(Me.txtbxDescription.Value)
End If
If rngItem.Offset(, 0).Value = "" Then
Cells(LastRow, 2).Value = Me.txtbxPrdctCde.Value
Else
rngItem.Offset(, 0).Value = Me.txtbxPrdctCde.Value
End If
If rngItem.Offset(, 1).Value = "" Then
Cells(LastRow, 3).Value = Application.Proper(Me.txtbxDescription.Value)
Else
rngItem.Offset(, 1).Value = Application.Proper(Me.txtbxDescription.Value)
End If
If rngItem.Offset(, 2).Value = Me.txtbxDzPrCs.Value Then
Cells(LastRow, 4).Value = Me.txtbxDzPrCs.Value
Else
rngItem.Offset(, 2).Value = Me.txtbxDzPrCs.Value
End If
If rngItem.Offset(, 3).Value = Me.txtbxCsPerPal.Value Then
Cells(LastRow, 5).Value = Me.txtbxCsPerPal.Value
Else
Cells(LastRow, 3).Value = Me.txtbxCsPerPal.Value
End If
If frmAddProduct.txtbxDzPrCs.Value = "" Then
MsgBox "Please enter dozens per case.", vbCritical + vbDefaultButton1 + vbOKOnly, "Missing: Dozens per case"
Me.txtbxDzPrCs.SetFocus
Exit Sub
Else
rngItem.Offset(, 2).Value = Me.txtbxDzPrCs.Value
End If
If frmAddProduct.txtbxCsPerPal.Value = "" Then
MsgBox "Please enter cases per pallet.", vbCritical + vbDefaultButton1 + vbOKOnly, "Missing: Cases per pallet"
Me.txtbxCsPerPal.SetFocus
Exit Sub
Else
rngItem.Offset(, 3).Value = Me.txtbxCsPerPal.Value
End If
For Each ctl In Me.Controls
If TypeName(ctl) = "OptionButton" Then
If ctl.Value = True Then
cnt = cnt + 1
Debug.Print "You have selected " & ctl.Caption
rngItem.Offset(, 4).Value = ctl.Caption
sUOM = ctl.Caption
End If
End If
Next ctl
If cnt = 0 Then
MsgBox "Please select a unit of measure (UOM).", vbCritical + vbDefaultButton1 + vbOKOnly, "Missing: Unit of Measure"
frmAddProduct.optEa.SetFocus
Exit Sub
End If
Unload Me
frmSDPFLineSelect.Show
End Sub
Code:
Function findItem(Rng As Range, sPrdCde As String) As Range
Set findItem = Rng.Find(sPrdCde, lookat:=xlPart)
End Function