Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 29
Default Macro to find last occurance

This is the code I have so far; however instead of finding the first
occurrence of what was entered into the input box, I need the last occurrence
in column C. Can anyone help?

Sub Insertinfo()
Dim FindWhat As String
Dim FoundCell As Range

FindWhat = InputBox("Find What", "Find")
If StrPtr(FindWhat) = 0 Then
Exit Sub
End If
On Error Resume Next
Set FoundCell = Range("c:c").Find(What:=FindWhat, _
LookAt:=xlWhole, LookIn:=xlValues)
If FoundCell Is Nothing Then
MsgBox "Not Found"
Else
FoundCell.Activate
With ActiveCell.EntireRow
.Copy
.Insert Shift:=xlDown
End With
End If
Application.CutCopyMode = False
End Sub

Thanks,
Holly
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default Macro to find last occurance

Try this

If you have more then one occurrence of the value this will
select the last occurrence in column C.

Sub Find_Last()
Dim FindString As String
Dim rng As Range
FindString = InputBox("Enter a Search value")
If Trim(FindString) < "" Then
With Sheets("Sheet1").Range("C:C")
Set rng = .Find(What:=FindString, _
After:=.Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
Else
MsgBox "Nothing found"
End If
End With
End If
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"hnyb1" wrote in message ...
This is the code I have so far; however instead of finding the first
occurrence of what was entered into the input box, I need the last occurrence
in column C. Can anyone help?

Sub Insertinfo()
Dim FindWhat As String
Dim FoundCell As Range

FindWhat = InputBox("Find What", "Find")
If StrPtr(FindWhat) = 0 Then
Exit Sub
End If
On Error Resume Next
Set FoundCell = Range("c:c").Find(What:=FindWhat, _
LookAt:=xlWhole, LookIn:=xlValues)
If FoundCell Is Nothing Then
MsgBox "Not Found"
Else
FoundCell.Activate
With ActiveCell.EntireRow
.Copy
.Insert Shift:=xlDown
End With
End If
Application.CutCopyMode = False
End Sub

Thanks,
Holly

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 29
Default Macro to find last occurance

Thank you much, especially for the quick response! It worked beautifully.

"Ron de Bruin" wrote:

Try this

If you have more then one occurrence of the value this will
select the last occurrence in column C.

Sub Find_Last()
Dim FindString As String
Dim rng As Range
FindString = InputBox("Enter a Search value")
If Trim(FindString) < "" Then
With Sheets("Sheet1").Range("C:C")
Set rng = .Find(What:=FindString, _
After:=.Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)
If Not rng Is Nothing Then
Application.Goto rng, True
Else
MsgBox "Nothing found"
End If
End With
End If
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"hnyb1" wrote in message ...
This is the code I have so far; however instead of finding the first
occurrence of what was entered into the input box, I need the last occurrence
in column C. Can anyone help?

Sub Insertinfo()
Dim FindWhat As String
Dim FoundCell As Range

FindWhat = InputBox("Find What", "Find")
If StrPtr(FindWhat) = 0 Then
Exit Sub
End If
On Error Resume Next
Set FoundCell = Range("c:c").Find(What:=FindWhat, _
LookAt:=xlWhole, LookIn:=xlValues)
If FoundCell Is Nothing Then
MsgBox "Not Found"
Else
FoundCell.Activate
With ActiveCell.EntireRow
.Copy
.Insert Shift:=xlDown
End With
End If
Application.CutCopyMode = False
End Sub

Thanks,
Holly


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find the 1st occurance of a number in a cell lovemuch Excel Worksheet Functions 4 August 17th 06 01:02 AM
Find next occurance Jambruins Excel Discussion (Misc queries) 5 August 10th 06 04:48 PM
Find last occurance of character in text string JDay01 Excel Worksheet Functions 2 February 14th 06 04:29 PM
Find last occurance of text in range farutherford Excel Worksheet Functions 5 August 30th 05 02:00 AM
frequency for each occurance bjg Excel Worksheet Functions 3 November 24th 04 02:13 PM


All times are GMT +1. The time now is 12:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"