vba Find function - Killing me

jimv

New Member
Joined
Feb 12, 2008
Messages
46
I am hoping someone can get me straight. I had this darn thing working earlier in the day and for some reason the code no longer works.

LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("A1:A" & LR)
Set LastCell = .Cells(.Cells.Count)
End With
Set FoundCell = Range("A1:A" & LR).Find(what:="Employee: ", After:=LastCell, Lookat:=x1Part)
If FoundCell.Address <> "$A$10" Then
MsgBox ("You need to use the Kronos time sheet.")
Exit Sub
End If

'Set FoundCell = Range("A1:A" & LR).Find(what:="Employee: ", after:=LastCell)
If Not FoundCell Is Nothing Then
FirstAddr = FoundCell.Address
End If


I have a large amount of data in column A and I am searching for the line that has the employee name on it. (See below)

(Employee: Lastname, Firstname ID: 124307 Time Zone: Eastern)

Right now the code stops becuase Foundcell ends up as "Nothing". It worked yesterday and eariler today so I know (hope) it works.

Please help! I am down to the last several hairs on my head.

Jim
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
I actually removed the back end of the statement and now it reads:
Set FoundCell = Range("A1:A" & LR).Find(what:="Employee: ", After:=LastCell)

If I close excel and then go back in, the routine runs perfectly. If I try to do it again (for another department), it will not work.
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,634
Members
452,934
Latest member
Jdsonne31

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top