• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 613
  • Last Modified:

excel vba range.find doesn't return a range

Dear experts,

I have this little piece of code and i can't get the find function to return the address or range of the cell.

i don't understand what i have to do. here's my code.

sub testFind()

Dim GSRNsp As String
Dim PlantnameSP As String
Dim Skownership As Integer
Dim MeasuringRfact As Integer
Dim rangeFind As Range
With Workbooks(WorkbookName).Sheets("DividedPD's")

    x = .Cells(Rows.Count, "J").End(xlUp).Row

For i = 2 To x

    GSRNsp = .Range("J" & i).Value 'this is a unique id nr like(703213102 stored as text)
    PlantnameSP = .Range("K" & i).Value
    Skownership = .Range("L" & i).Value
    MeasuringRfact = .Range("M" & i).Value

Set rangeFind = Workbooks(targetSheetName).Sheets(tabName).Range("3:3").Find(What:=GSRNsp, After:=Range("A3"), SearchOrder:=xlByColumns)

'rangefind will now return the unique id like (703213102) while it should return the range 'or something?

next i

end with 

Open in new window



Thank you!

Mark
0
MarkVrenken
Asked:
MarkVrenken
  • 2
1 Solution
 
MarkVrenkenAuthor Commented:
ps this is just a piece of the code. The other workbook is first opened
0
 
MarkVrenkenAuthor Commented:
added this and it works:)

If Not rangeFind Is Nothing Then

ColumnNumber = rangeFind.Column
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now