search,find and remove

classicbm

New Member
Joined
Mar 18, 2011
Messages
5
hi , I need to search a large group of columns to find for example Honda CG125, when all are found remove them to a separate spreadsheet , is it possible , need help urgently
William:confused:
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
classicbm,

What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples (what you have and what you expect to achieve) directly in the forum.

To attach screenshots, see below in my Signature block: Post a screen shot with one of these:
 
Upvote 0
hi , I need to search a large group of columns to find for example Honda CG125, when all are found remove them to a separate spreadsheet , is it possible , need help urgently
William:confused:

I am using 2007
and i want to extract for example all the suzuki columns and place them in a different spreedsheet
Excel Workbook
AB
8018356542Rear Light Lens Kawasaki KH250,Z900,Z1000
8019356546Rear Light Lens Kawasaki KLR250,KLR600 (E-Marked)
8020356772Rear Light Lens Kawasaki EN500,ZR550B Zephyr,KLZ650
8021356775Rear Light Lens Kawasaki GPZ,GT Air-Cooled
8022356805Rear Light Lens Kawasaki GPZ600,GPZ750R,GPZ900R
8023356825Rear Light Lens Kawasaki KLR650A
8024357004Rear Light Lens Suzuki AH50 Address
8025357020Rear Light Lens Suzuki CS50 Roadie
8026357025Rear Light Lens Suzuki FR50,AP50,AP100
8027357065Rear Light Lens Suzuki TS50-TS185ER
8028357070Rear Light Lens Suzuki TS50X,TS125X,RGV250
8029357290Rear Light Lens Suzuki GP100,GP125
8030357340Rear Light Lens Suzuki DR125,TS125ERZ
8031357350Rear Light Lens Suzuki GS125,ZR50
8032357540Rear Light Lens Suzuki GSX250,GSX400 Twin
8033357552Rear Light Lens Suzuki X7,X5,SP400
8034357635Rear Light Lens Suzuki T250,T350,T500
8035357640Rear Light Lens Suzuki GT380-GT750 Range
8036357785Rear Light Lens Suzuki GS250-GS750 Range
8037358000Rear Light Lens Yamaha Early Models
8038358010Rear Light Lens Yamaha RD50,DT50,TY50M
8039358015Rear Light Lens Yamaha FS1E Early
8040358019Rear Light Lens Yamaha MS50,New FS1
8041358057Rear Light Lens Yamaha RD50MX,DT50MX (G0)
8042358060Rear Light Lens Yamaha SA50 Passola
8043358310Rear Light Lens Yamaha RXS100
8044358347Rear Light Lens Yamaha DT125LC Mk1
8045358349Rear Light Lens Yamaha DT125R,DT125LC Mk2,3, Aprilia RX50
8046358365Rear Light Lens Yamaha RD LC,DT,MX,XT
8047358380Rear Light Lens Yamaha TZR125,RD500
2011
Excel 2007
 
Upvote 0
classicbm,

I assume that your raw data is in worksheet 2011, and that the data only contains columns A and B. And, there are titles in row 1.

The Yellow cell, D1, is where you would enter the search cirteria.

The Blue cell, E1, will count how cells in column B contain the search criteria.

If cell D1 is blank, or if cell E1 is 0 (zero) you will get a message box, and the macro will terminate.


Sample raw data in worksheet 2011:


Excel Workbook
ABCDE
1Title ATitle B**0
2356542Rear Light Lens Kawasaki KH250,Z900,Z1000***
3356546Rear Light Lens Kawasaki KLR250,KLR600 (E-Marked)***
4356772Rear Light Lens Kawasaki EN500,ZR550B Zephyr,KLZ650***
5356775Rear Light Lens Kawasaki GPZ,GT Air-Cooled***
6356805Rear Light Lens Kawasaki GPZ600,GPZ750R,GPZ900R***
7356825Rear Light Lens Kawasaki KLR650A***
8357004Rear Light Lens Suzuki AH50 Address***
9357020Rear Light Lens Suzuki CS50 Roadie***
10357025Rear Light Lens Suzuki FR50,AP50,AP100***
11357065Rear Light Lens Suzuki TS50-TS185ER***
12357070Rear Light Lens Suzuki TS50X,TS125X,RGV250***
13357290Rear Light Lens Suzuki GP100,GP125***
14357340Rear Light Lens Suzuki DR125,TS125ERZ***
15357350Rear Light Lens Suzuki GS125,ZR50***
16357540Rear Light Lens Suzuki GSX250,GSX400 Twin***
17357552Rear Light Lens Suzuki X7,X5,SP400***
18357635Rear Light Lens Suzuki T250,T350,T500***
19357640Rear Light Lens Suzuki GT380-GT750 Range***
20357785Rear Light Lens Suzuki GS250-GS750 Range***
21358000Rear Light Lens Yamaha Early Models***
22358010Rear Light Lens Yamaha RD50,DT50,TY50M***
23358015Rear Light Lens Yamaha FS1E Early***
24358019Rear Light Lens Yamaha MS50,New FS1***
25358057Rear Light Lens Yamaha RD50MX,DT50MX (G0)***
26358060Rear Light Lens Yamaha SA50 Passola***
27358310Rear Light Lens Yamaha RXS100***
28358347Rear Light Lens Yamaha DT125LC Mk1***
29358349Rear Light Lens Yamaha DT125R,DT125LC Mk2,3, Aprilia RX50***
30358365Rear Light Lens Yamaha RD LC,DT,MX,XT***
31358380Rear Light Lens Yamaha TZR125,RD500***
32*****
2011




If we enter Suzuki into cell D1, cell E1 will display 13.


If we run the macro, we will get:


Excel Workbook
AB
1Title ATitle B
2357004Rear Light Lens Suzuki AH50 Address
3357020Rear Light Lens Suzuki CS50 Roadie
4357025Rear Light Lens Suzuki FR50,AP50,AP100
5357065Rear Light Lens Suzuki TS50-TS185ER
6357070Rear Light Lens Suzuki TS50X,TS125X,RGV250
7357290Rear Light Lens Suzuki GP100,GP125
8357340Rear Light Lens Suzuki DR125,TS125ERZ
9357350Rear Light Lens Suzuki GS125,ZR50
10357540Rear Light Lens Suzuki GSX250,GSX400 Twin
11357552Rear Light Lens Suzuki X7,X5,SP400
12357635Rear Light Lens Suzuki T250,T350,T500
13357640Rear Light Lens Suzuki GT380-GT750 Range
14357785Rear Light Lens Suzuki GS250-GS750 Range
15**
Suzuki





Excel Workbook
ABCDE
1Title ATitle B*Suzuki0
2356542Rear Light Lens Kawasaki KH250,Z900,Z1000***
3356546Rear Light Lens Kawasaki KLR250,KLR600 (E-Marked)***
4356772Rear Light Lens Kawasaki EN500,ZR550B Zephyr,KLZ650***
5356775Rear Light Lens Kawasaki GPZ,GT Air-Cooled***
6356805Rear Light Lens Kawasaki GPZ600,GPZ750R,GPZ900R***
7356825Rear Light Lens Kawasaki KLR650A***
8358000Rear Light Lens Yamaha Early Models***
9358010Rear Light Lens Yamaha RD50,DT50,TY50M***
10358015Rear Light Lens Yamaha FS1E Early***
11358019Rear Light Lens Yamaha MS50,New FS1***
12358057Rear Light Lens Yamaha RD50MX,DT50MX (G0)***
13358060Rear Light Lens Yamaha SA50 Passola***
14358310Rear Light Lens Yamaha RXS100***
15358347Rear Light Lens Yamaha DT125LC Mk1***
16358349Rear Light Lens Yamaha DT125R,DT125LC Mk2,3, Aprilia RX50***
17358365Rear Light Lens Yamaha RD LC,DT,MX,XT***
18358380Rear Light Lens Yamaha TZR125,RD500***
19*****
20*****
21*****
22*****
23*****
24*****
25*****
26*****
27*****
28*****
29*****
30*****
31*****
32*****
2011





If we enter in cell D1 Yamaha RXS100 and then run the macro:


Excel Workbook
ABCDE
1Title ATitle B*Yamaha RXS1001
2356542Rear Light Lens Kawasaki KH250,Z900,Z1000***
3356546Rear Light Lens Kawasaki KLR250,KLR600 (E-Marked)***
4356772Rear Light Lens Kawasaki EN500,ZR550B Zephyr,KLZ650***
5356775Rear Light Lens Kawasaki GPZ,GT Air-Cooled***
6356805Rear Light Lens Kawasaki GPZ600,GPZ750R,GPZ900R***
7356825Rear Light Lens Kawasaki KLR650A***
8358000Rear Light Lens Yamaha Early Models***
9358010Rear Light Lens Yamaha RD50,DT50,TY50M***
10358015Rear Light Lens Yamaha FS1E Early***
11358019Rear Light Lens Yamaha MS50,New FS1***
12358057Rear Light Lens Yamaha RD50MX,DT50MX (G0)***
13358060Rear Light Lens Yamaha SA50 Passola***
14358310Rear Light Lens Yamaha RXS100***
15358347Rear Light Lens Yamaha DT125LC Mk1***
16358349Rear Light Lens Yamaha DT125R,DT125LC Mk2,3, Aprilia RX50***
17358365Rear Light Lens Yamaha RD LC,DT,MX,XT***
18358380Rear Light Lens Yamaha TZR125,RD500***
19*****
2011





Excel Workbook
AB
1Title ATitle B
2358310Rear Light Lens Yamaha RXS100
3**
Yamaha RXS100





And then we are left with:


Excel Workbook
ABCDE
1Title ATitle B*Yamaha RXS1000
2356542Rear Light Lens Kawasaki KH250,Z900,Z1000***
3356546Rear Light Lens Kawasaki KLR250,KLR600 (E-Marked)***
4356772Rear Light Lens Kawasaki EN500,ZR550B Zephyr,KLZ650***
5356775Rear Light Lens Kawasaki GPZ,GT Air-Cooled***
6356805Rear Light Lens Kawasaki GPZ600,GPZ750R,GPZ900R***
7356825Rear Light Lens Kawasaki KLR650A***
8358000Rear Light Lens Yamaha Early Models***
9358010Rear Light Lens Yamaha RD50,DT50,TY50M***
10358015Rear Light Lens Yamaha FS1E Early***
11358019Rear Light Lens Yamaha MS50,New FS1***
12358057Rear Light Lens Yamaha RD50MX,DT50MX (G0)***
13358060Rear Light Lens Yamaha SA50 Passola***
14358347Rear Light Lens Yamaha DT125LC Mk1***
15358349Rear Light Lens Yamaha DT125R,DT125LC Mk2,3, Aprilia RX50***
16358365Rear Light Lens Yamaha RD LC,DT,MX,XT***
17358380Rear Light Lens Yamaha TZR125,RD500***
18*****
2011





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub SearchCopyDelete()
' hiker95, 07/11/2011
' http://www.mrexcel.com/forum/showthread.php?t=563104
Dim w1 As Worksheet, wR As Worksheet
Dim LR As Long, NR As Long
Set w1 = Worksheets("2011")
w1.AutoFilterMode = False
If Range("D1") = "" Or Range("E1") = 0 Then
  MsgBox "There is no search criteria in cell D1" & vbLf & _
    "or, cell E1 displays a zero - macro terminated!"
  Exit Sub
End If
Application.ScreenUpdating = False
If Not Evaluate("ISREF(" & w1.Range("D1") & "!A1)") Then Worksheets.Add(After:=w1).Name = w1.Range("D1").Value
Set wR = Worksheets(w1.Range("D1").Value)
wR.Range("A1:B1").Value = w1.Range("A1:B1").Value
LR = w1.Cells(Rows.Count, 1).End(xlUp).Row
With w1.Range("A1:B" & LR)
  .AutoFilter Field:=2, Criteria1:="=*" & w1.Range("D1").Value & "*", Operator:=xlAnd
  NR = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
  .Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy wR.Range("A" & NR)
  .Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).EntireRow.Delete
  .AutoFilter
End With
wR.UsedRange.Columns.AutoFit
wR.Activate
Application.ScreenUpdating = True
End Sub



Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Then run the SearchCopyDelete macro.
 
Upvote 0
classicbm,

All the * characters in the screenshots should not show up in your worksheets.

I did not check after copying your screenshot for space characters in empty cells.
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,308
Members
452,904
Latest member
CodeMasterX

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