Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Quick Search of Workbook VBA Macro

0

I am attempting to search a workbook filled with data utilizing the "fast search" VBA code.  I have changed the necessary items relative to my workbook and am receiving a run time error (imagine that?) #9 at line 

'Check if the value in the row equals our search value

            If (dataArray(i, searchField) = searchValue) Then

If any of this makes sense I would appreciate a shout back.  

thanks,  If (dataArray(i, searchField) = searchValue) Then

Rob

Answer
Discuss

Answers

0

Error #9 means "Subscript out of range", and in this case it means that the coordinates i and searchField do not correctly define an element of the array dataArray.

To begin, both i and searchField must be integers, not necessarily of Integer type but without decimals. They must both be positive. They must be >= LBound(dataArray) and <= UBound(dataArray) for i and  >= LBound(dataArray, 2) and <= UBound(dataArray, 2)  for searchField respectively.

If this array contains values taken from a worksheet range, bear in mind that i defines the row and searchField  the column.

Another good way is to look at the Locals window immediately after the crash. There you will find all values of dataArray listed with their coordinates.

Discuss

Discussion

You're amazing Variatus.  Thank you.  I will take a look back over the code and look at the "Locals" window. 
Team61984 Apr 29, '20 at 3:34 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login