Variable not set
you have a few problems:
1. don't use row and column as variables. they ar keywords in excel.
2. you need to test if the value you're finding is actually found.
this isn't perfect because i can't test against what you have. if it doesn't
find a row or column, you will have a problem. use this as a guide
Sub DirectLabor()
Dim Category
Dim Period
Dim iRow
Dim iColumn
Dim Comment
Dim rFound As Range
Dim cFound As Range
Dim ws As Worksheet
Category = Sheet2.Range("A1") & Sheet2.Range("A77")
Period = Sheet2.Range("B3")
Set ws = Worksheets("Sheet24")
With ws
Set rFound = ws.Cells.Find(What:=Category, After:=ws.Cells(1, 1),
LookIn:=xlValues)
If Not rFound Is Nothing Then
iRow = rFound.Row
End If
Set cFound = ws.Cells.Find(What:=Period, After:=ws.Cells(1, 1),
LookIn:=xlValues)
If Not cFound Is Nothing Then
iColumn = cFound.Column
End If
End With
On Error Resume Next
Comment = ws.Cells(iRow, iColumn).Text
On Error GoTo 0
If Comment < "" Then
Frm1.Txt.Text = Comment
Frm1.Show
Else
MsgBox "data not found"
End If
End Sub
|