Searching within spreadsheet

Sara R.

Board Regular
Joined
Jul 12, 2007
Messages
64
Is there a way to search for a specific word or letters within a cell and copy the contents of that cell to another location? For instance, I'm looking for cells within a spreadsheet and within one column that contain AE. An example of a cell with AE in it would be:

.ASSY, AE3010-32X224-7.6mm-422-120V

The amount of letters in front of AE or behind it can vary. I want to find all of the cells that contain AE and copy the contents to a column in another worksheet. Any ideas??

Thanks!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi Sara

You're looking at a VBA solution here to do this - is this OK? Also, do you want the search to be case sensitive or Case-insensitive (ie do you want AE to be different from ae or aE etc)?
 
Upvote 0

Sara R.

Board Regular
Joined
Jul 12, 2007
Messages
64
Yeah, a VBA solution would be fine if you tell me how to do it :) I've never done it before. I definitely need it to be able to find all forms of AE - so case insensitive.

Thanks!
 
Upvote 0

MarkAndrews

Well-known Member
Joined
May 2, 2006
Messages
1,970
Office Version
  1. 2010
Platform
  1. Windows
You could try this?

(A1 being the cell where .ASSY, AE3010-32X224-7.6mm-422-120V
is located)


=IF(COUNTIF(A1,"*AE*"),A1,"")
 
Upvote 0

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Sara

Give the following a try - it needs to go into a standard module in the workbook and you need to change the sheet name in the place indicated to whatever is appropriate.

Code:
Sub Get_Data()
Dim rAll As Range, rData As Range, sSearchString As String, ws As Worksheet
sSearchString = "AE"
With Sheets("Sheet2") 'change as appropriate
   Set rAll = .Range("A1:A" & .Cells(Rows.Count, "A").End(xlUp).Row)
End With
With rAll
   .AutoFilter Field:=1, Criteria1:="*" & sSearchString & "*"
   If .Find(What:=sSearchString, LookAt:=xlPart, MatchCase:=False) Is Nothing Then
      MsgBox "Searched for term " & sSearchString & " not found!"
      .AutoFilter
      Exit Sub
   Else
      Set rData = .Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
      Set ws = Worksheets.Add
      rData.Copy Destination:=ws.Range("A1")
      .AutoFilter
   End If
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,191,719
Messages
5,988,290
Members
440,148
Latest member
sandy123

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
Top