View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ExcelMonkey ExcelMonkey is offline
external usenet poster
 
Posts: 553
Default Using Offset on Variable Dinensioneds Object

I have passed a range of data to a variable (PMSMatchRange) that I have
dimensioned as an Object. My first For Next loop below works correctly.
However when I get into my second For Next Loop, I cannot seem to use the
Offset Method on the PMSMatchRange variable:

CorrectCompanyName = PMSMatchRange.Offset(MatchNumber - 1, 1)

Is this because it is an object? Effectively I am tyring to do a lookup off
1 column to the right of the range that I passed to this variable. Thanks

ImportSheetVbNm.Select
ImportSheetVbNm.Range("B2").Select
ImportSheetVbNm.Range(Selection, Selection.End(xlDown)).Select
NumPMSCodes = Selection.Rows.Count

vbPMSCodeList.Select
vbPMSCodeList.Range("A2").Select
vbPMSCodeList.Range(Selection, Selection.End(xlDown)).Select

Set PMSMatchRange = vbPMSCodeList.Range(Selection,
Selection.End(xlDown))

For X = 1 To NumPMSCodes
ImportSheetVbNm.Select
ImportSheetVbNm.Range("B2").Offset(X - 1, 0).Select
If IsError(Application.Match(ActiveCell.Value, PMSMatchRange,
0)) Then
MsgBox ("You have PMS Codes in your import sheet that do not
exist in your PMS Master List.")
ActiveCell.EntireRow.Select
Exit Sub
End If
Next

For X = 1 To NumPMSCodes
ImportSheetVbNm.Select
ImportSheetVbNm.Range("B2").Offset(X - 1, 0).Select
MatchNumber =
Application.WorksheetFunction.Match(ActiveCell.Val ue, PMSMatchRange, 0)
CorrectCompanyName = PMSMatchRange.Offset(MatchNumber - 1, 1)
ImportSheetVbNm.Range("C2").Offset(X - 1, 0) = CorrectCompanyName
Next