jdgalaway
08-05-2014, 07:18 PM
Can someone please take a look at my code. I'm having trouble figuring out what is causing this error.
I'm using a simple hlookup worksheetfunction, and I'm getting a runtime error 1004. The code that I included is a simplified version of a much larger macro. I've indicated in which row the error occurs, but please let me know if you need any additional information.
I appreciate it.
Sub Test()
Dim i As Integer
For i = 1 To 23
Dim numRows As Integer
Dim netRows As Integer
Dim psmLook As Variant
Dim psmVal As Variant
Dim psmRange As Range
Dim psmNum As Range
numRows = 23
netRows = 504
psmVal = Worksheets("DetailedSummary").Cells(i + 3, 34)
'This is supposed to be all one line. Also, the below line is probably what is causing the error below.
Set psmRange = Workbooks("Book1").Worksheets("Solve").Range(Workbooks("Book1").Worksheets("Solve").Cells(numRows + 7, 6),
Workbooks("Book1").Worksheets("Solve").Cells(numRows + numRows + 7, netRows + 5))
Set psmNum = Worksheets("Solve").Cells(numRows + 7 + i, 4)
psmLook = Application.WorksheetFunction.HLookup(psmVal, psmRange, psmNum, False) <----Error Occurs Here!!!!
If Err.Number <> 0 Then
Worksheets("DetailedSummary").Cells(i + 3, 33).Value = 0
Else
Worksheets("DetailedSummary").Cells(i + 3, 33).Value = psmLook
End If
Next
End Sub
I'm using a simple hlookup worksheetfunction, and I'm getting a runtime error 1004. The code that I included is a simplified version of a much larger macro. I've indicated in which row the error occurs, but please let me know if you need any additional information.
I appreciate it.
Sub Test()
Dim i As Integer
For i = 1 To 23
Dim numRows As Integer
Dim netRows As Integer
Dim psmLook As Variant
Dim psmVal As Variant
Dim psmRange As Range
Dim psmNum As Range
numRows = 23
netRows = 504
psmVal = Worksheets("DetailedSummary").Cells(i + 3, 34)
'This is supposed to be all one line. Also, the below line is probably what is causing the error below.
Set psmRange = Workbooks("Book1").Worksheets("Solve").Range(Workbooks("Book1").Worksheets("Solve").Cells(numRows + 7, 6),
Workbooks("Book1").Worksheets("Solve").Cells(numRows + numRows + 7, netRows + 5))
Set psmNum = Worksheets("Solve").Cells(numRows + 7 + i, 4)
psmLook = Application.WorksheetFunction.HLookup(psmVal, psmRange, psmNum, False) <----Error Occurs Here!!!!
If Err.Number <> 0 Then
Worksheets("DetailedSummary").Cells(i + 3, 33).Value = 0
Else
Worksheets("DetailedSummary").Cells(i + 3, 33).Value = psmLook
End If
Next
End Sub