VBA to find the last occurrence of a word and select that word

adamolivier

New Member
Joined
Nov 18, 2015
Messages
15
I am trying to use the Find function to find the last location that a word is used in column A. Below is my current code. I have tried various other versions and methods, but cannot seem to figure this out.

Code:
Sub Find()


Range("a10000").End(xlUp).Select
Range("a:a").Find("Count").Select




End Sub

Any suggestions?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
How about
Code:
Sub FindLast()
   Dim Fnd As Range
   Set Fnd = Range("A:A").find("count", , , xlPart, xlByRows, xlPrevious, False, , False)
End Sub
 
Upvote 0
How about
Code:
Sub FindLast()
   Dim Fnd As Range
   Set Fnd = Range("A:A").find("count", , , xlPart, xlByRows, xlPrevious, False, , False)
End Sub

That worked.

How would I expand this to select all rows from the last occurrence of "count" to the last occurrence of "totals"?

Thanks
 
Upvote 0
Like
Code:
Sub FindLast()
   Dim Fnd1 As Range, Fnd2 As Range
   Set Fnd1 = Range("A:A").find("count", , , xlPart, xlByRows, xlPrevious, False, , False)
   Set Fnd2 = Range("A:A").find("totals", , , xlPart, xlByRows, xlPrevious, False, , False)
   Range(Fnd1, Fnd2).EntireRow.Select
End Sub
 
Upvote 0
That did work.

Here is what I have now:
Code:
Sub FindLast()
   Dim Fnd1 As Range, Fnd2 As Range
   Set Fnd2 = Range("A:A").Find("totals", , , xlPart, xlByRows, xlPrevious, False, , False)
   Set Fnd1 = Range("A:A").Find("count", , , xlPart, xlByRows, xlPrevious, False, , False)
   Range(Fnd1, Fnd2).EntireRow.Select
   Selection.Copy
   ActiveCell.Select
End Sub

I am trying to have the rows selected, copied, then paste 3 rows below the word "totals". I have tried doing it a couple of ways, but am having a hard time getting it to work. The above code selects the active cell, but that is the word "count".

Thanks for all of your help.
 
Upvote 0
How about
Code:
Sub FindLast()
   Dim Fnd1 As Range, Fnd2 As Range
   Set Fnd1 = Range("A:A").find("count", , , xlPart, xlByRows, xlPrevious, False, , False)
   Set Fnd2 = Range("A:A").find("totals", , , xlPart, xlByRows, xlPrevious, False, , False)
   Range(Fnd1, Fnd2).EntireRow.Copy Fnd2.Offset(3)
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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