Thread: find location
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] paul.robinson@it-tallaght.ie is offline
external usenet poster
 
Posts: 789
Default find location

Hi
Cells(1) in your Find is the first cell on the worksheet. Since you
are looking in row 13 the Find Method is getting upset. You can also
catch the error if the value is not found using On Error as below.

On Error Resume Next
Set CurLocation = ActiveSheet.Rows(13).Find(What:=curDate.Value, _
After:=Rows(13).Cells(1, 1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)


Dim rng As Range
Set rng = Range(CurLocation.Address)
Debug.Print (rng)
On Error GoTo 0

Finally, you use Address as a variable name. Not a good idea, as it is
a VBA property of a Range - try CurAddress or something.

regards
Paul

On Feb 1, 5:11*am, Jim G wrote:
I'm trying to set the current selection to an address on a row that contain
dates equal to the end of each monht and matches the current date on a data
page (month ends muct match). *The following code returns a type mismatch
error. *Can any one help

Sub FindCurMonth()

Dim CurLocation As Range

Dim curDate As Range

Set curDate = Range("B3")

* * Set CurLocation = Rows(13).Find(What:=curDate.Value, _
* * * * After:=Cells(1), _
* * * * LookIn:=xlValues, _
* * * * LookAt:=xlWhole, _
* * * * SearchOrder:=xlByRows, _
* * * * SearchDirection:=xlNext, _
* * * * MatchCase:=False, _
* * * * SearchFormat:=False)

Dim rng As Range
Set rng = Range(CurLocation.Address)
Debug.Print (rng)

If Not CurLocation Is Nothing Then
* * Address = CurLocation.Address
* * CurLocation.Select
Else
* * MsgBox "Not found"
End If
End Sub

--
Jim