Excel/faster search method?
I have a working search function on my spreadsheet, my question is can I make this any quicker and use a more efficient method of coding it in VBA?
I have number of worksheets with data I wish to reference in column D, the cells vary in number from 2 to 115 (d2:D115). I am currently using a select case method and have included a snippet below. This code is repeated for each worksheet.
private sub search()
' declare variables
Dim cell As Range
Select Case QualCategory
Case Is = "Gas Utilisation (Downstream)"
' Set the area within the sheet to be searched
For Each cell In Range("d2: d115")
If cell.Value = QualNum Then
Category = cell.Offset(0, 2).Value
msg = msg & Category
this is repeated for every worksheet, instead of coding for when a user input is not found I have used an error handler like below
Category = "Not Recognised by ACS"
msg = msg & Category
It seemed simpler to write this once and treat the not found as an error rather than duplicating the code 8 times.
Is it possible to cycle my search through the worksheets without having to specify the name of each one? and if so how could I do this? my concern really is that coding is not excessive for 8 sheets but what do I do when I have say 50 sheets or more?
look like you are using a userform (QualSearch.hide) and I don't know if you are doing exactly the same thing to each sheet and so forth but here is some general pseudo code that show looping through sheets and using the worksheet function countif to determine if a value exists in column D. It processes all sheets but excludes the "Introduction" sheet.
Dim sh as worksheets, r as range
for each sh in worksheets
if lcase(sh.name) <> "introduction" then
set r = sh.Range("D:D")
if application.countif(r, Qualnum) > 0 then
' action to take
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here