Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default Create a macro that finds values then sorts

Sorry if this questions has been asked recently. I have searched for an
answer to no avail.

I'm trying to write a macro that will search an excel spreadsheet for exact
text. Once if finds the exact text match(es)
it should then assign a value to a cell in the same row (maybe yes or no)
then it should sort the list by rows that match delete the rest.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,939
Default Create a macro that finds values then sorts

This is not too bad to do but I highly recommend not deleting the extra
lines. Once deleted they are gone never to return. I promise you that at some
point something will happend and the wrong stuff will be deleted and there
will be no way back. Or someone will swear that it deleted the wrong thing
and you will have no way to prove that the item never existed. I recommend
leaving the source data alone and copying out the found data to a new sheet.
Something like this...(This sub looks for the word "This" in Sheet1, Column
A...

Public Sub CopyFoundStuff()
Dim wksCopyTo As Worksheet
Dim wksCopyFrom As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String

Set wksCopyFrom = Sheets("Sheet1")
Set rngToSearch = wksCopyFrom.Columns("A")
Set rngFound = rngToSearch.Find(What:="This", _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry ""This"" was not found."
Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
Set wksCopyTo = Worksheets.Add
rngFoundAll.EntireRow.Copy wksCopyTo.Range("A2")
End If

End Sub

--
HTH...

Jim Thomlinson


"John Hughes" wrote:

Sorry if this questions has been asked recently. I have searched for an
answer to no avail.

I'm trying to write a macro that will search an excel spreadsheet for exact
text. Once if finds the exact text match(es)
it should then assign a value to a cell in the same row (maybe yes or no)
then it should sort the list by rows that match delete the rest.

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default Create a macro that finds values then sorts


Thanks for your reply Jim. I'm still a bit lost.
I realize that I need to study macros a bit more. I did post this question
in the programming group. Can you provide me a list of changes/next steps in
order for me to use this Sub?

I know I need to change the column, "this" ( how do I list and seperate the
dozen strings of text?)

what else?



"Jim Thomlinson" wrote:

This is not too bad to do but I highly recommend not deleting the extra
lines. Once deleted they are gone never to return. I promise you that at some
point something will happend and the wrong stuff will be deleted and there
will be no way back. Or someone will swear that it deleted the wrong thing
and you will have no way to prove that the item never existed. I recommend
leaving the source data alone and copying out the found data to a new sheet.
Something like this...(This sub looks for the word "This" in Sheet1, Column
A...

Public Sub CopyFoundStuff()
Dim wksCopyTo As Worksheet
Dim wksCopyFrom As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String

Set wksCopyFrom = Sheets("Sheet1")
Set rngToSearch = wksCopyFrom.Columns("A")
Set rngFound = rngToSearch.Find(What:="This", _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
MatchCase:=False)
If rngFound Is Nothing Then
MsgBox "Sorry ""This"" was not found."
Else
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
Set wksCopyTo = Worksheets.Add
rngFoundAll.EntireRow.Copy wksCopyTo.Range("A2")
End If

End Sub

--
HTH...

Jim Thomlinson


"John Hughes" wrote:

Sorry if this questions has been asked recently. I have searched for an
answer to no avail.

I'm trying to write a macro that will search an excel spreadsheet for exact
text. Once if finds the exact text match(es)
it should then assign a value to a cell in the same row (maybe yes or no)
then it should sort the list by rows that match delete the rest.

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
Using a macro to create a macro in another workbook Gizmo63 Excel Worksheet Functions 2 May 15th 06 09:48 AM
How do I create a macro that will compare columns and place data CompuCat Excel Worksheet Functions 0 March 20th 06 06:21 PM
Vb macro stops when I try to create more than 89 charts Tiberius Charts and Charting in Excel 0 January 19th 06 05:52 PM
formatting date-time values in macro scw-tzg Excel Worksheet Functions 2 November 14th 05 09:21 PM
create a list of single values from multiple values Jordan Excel Worksheet Functions 3 November 3rd 05 11:25 PM


All times are GMT +1. The time now is 02:09 PM.

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

About Us

"It's about Microsoft Excel"