VBA - search and extract

j0rdan

New Member
Joined
Feb 28, 2014
Messages
2
Hi,

This has probably been discussed at length already but i'm unable to find a response that is suitable to my needs.

My problem is that whilst dealing with large datasets, i'd like to be able to create a macro which will give me a pop up box to input different types of keys words to search within a dataset. Once these keys words have been found, i would like excel to highlight the entire line so it can be extracted into a new worksheet.

I'm quite new to the world of macros so anything which isn't a recorded macro is a bit out of my depth, any help would be massively appreciated.

Cheers
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi,

This has probably been discussed at length already but i'm unable to find a response that is suitable to my needs.

My problem is that whilst dealing with large datasets, i'd like to be able to create a macro which will give me a pop up box to input different types of keys words to search within a dataset. Once these keys words have been found, i would like excel to highlight the entire line so it can be extracted into a new worksheet.

I'm quite new to the world of macros so anything which isn't a recorded macro is a bit out of my depth, any help would be massively appreciated.

Cheers

Welcome to MrExcel Forum
Copy this code to your standard code module. To access the code module, press Alt + F11. If the large pane is dark then click Insert>Module. If you want to keep the macro, then be sure your workbook is saved as a macro enabled workbook (.xlsm)
Code:
Sub searchStuff()
Dim sh As Worksheet, str As String, fLoc as Range
Set sh = Sheets(1) 'Edit sheet name
str = InputBox("Enter string to search.", "SEARCH ITEM")
 If str = "" Then Exit Sub
Set fLoc = sh.UsedRange.Find(str, , xlValues, xlWhole)
 If Not fLoc Is Nothing Then
  fLoc.EntireRow.Interior.ColorIndex = 6
 End If
End Sub
 
Upvote 0
Welcome to MrExcel Forum
Copy this code to your standard code module. To access the code module, press Alt + F11. If the large pane is dark then click Insert>Module. If you want to keep the macro, then be sure your workbook is saved as a macro enabled workbook (.xlsm)
Code:
Sub searchStuff()
Dim sh As Worksheet, str As String, fLoc as Range
Set sh = Sheets(1) 'Edit sheet name
str = InputBox("Enter string to search.", "SEARCH ITEM")
 If str = "" Then Exit Sub
Set fLoc = sh.UsedRange.Find(str, , xlValues, xlWhole)
 If Not fLoc Is Nothing Then
  fLoc.EntireRow.Interior.ColorIndex = 6
 End If
End Sub


Thanks for your response :) Unfortunately the code doesn't seme to do anything. I've tried with a basic search i.e. something i can already see but nothing happens? After i've entered my word (administration) and press ok/return i get returned to my spread sheet with no changes?
 
Upvote 0
Please explain what you mean by "The code doesn't seem to do anything". It worked as expected in testing. If the code was copied to the standard code module it should find the string entered into the inputbox, if the string is also in the worksheet somewhere, unless the string is embedded in another string. If your target string is not stand alone, then change the xlWhole in the find statement to xlPart.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,425
Members
448,961
Latest member
nzskater

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