find & replace value a cell

B

bijan

Hi
I found a helpful code from Mr.Thomlinson about find last item (Q1 in row 5)
___A___B____C___
1|Q1 aaa ZZ
2|Q1 bbb ZZ
3|Q1 ccc BB
4|Q1 ddd HH
5|Q1 eee GG
6|Q2 fff ZZ
7|Q2 ggg MM
the code is:
Public Sub FindLast()
Dim rngFound As Range
Dim rngToSearch As Range
Set rngToSearch = Range("A2", Cells(Rows.Count, "A").End(xlUp))
Set rngFound = rngToSearch.Find(What:="Q1", _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchDirection:=xlPrevious)
If rngFound Is Nothing Then
MsgBox "Sorry... Not Found"
Else
MsgBox "Found on row " & rngFound.Row
End If
End Sub
is it possible, I change "GG" in column C with "OK" in this code?
instead of MsgBox "Found on row " & rngFound.Row
any help appreciated
Bijan
 
D

Don Guillett

How about

cells(rngfound.row,"c")="OK"

Since your q1 is sorted you could also use

Sub findlastq1()
fr = WorksheetFunction.Match("q1", Columns("a"), 1)
'MsgBox fr
cells(fr,3)="OK"
End Sub
 
B

bijan

Thanks a lot, It works greate
but, if Q1 isn't sorted is there any way to done it
Many Regards
Bijan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top