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
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,253
Office Version
2013
Platform
Windows
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
 

j0rdan

New Member
Joined
Feb 28, 2014
Messages
2
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?
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,253
Office Version
2013
Platform
Windows
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:

Forum statistics

Threads
1,081,523
Messages
5,359,263
Members
400,523
Latest member
ExcelNewbie98

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top