Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Using Array variable in FIND function

You have to define SearchIn as an array, not a range. Also, SearchIn(n) will
not work as n is not defined. I think the structure you're looking for might
look something like this. I assume you have a loop set up that increments
the variable "i". If you are looping through a range and want every cell
that contains the values you're looking for, you could use the Union function
instead of Exit For (in the Else statement).

Dim SearchIn(1 To 2) As String
Dim Rngia As Range
Dim n As Long

SearchIn(1) = "*employment *government"
SearchIn(2) = "*employment *manufacturing"

For n = LBound(SearchIn) To UBound(SearchIn)
If Rngia Is Nothing Then
Set Rngia = Cells(i, 1).Find(What:=SearchIn(n), _
LookIn:=xlValues, Lookat:=xlPart)
Else: Exit For
End If
Next n
With the Union function

Dim SearchIn(1 To 2) As String
Dim Rngia As Range
Dim n As Long
Dim i As Long

On Error Resume Next

SearchIn(1) = "*employment *government"
SearchIn(2) = "*employment *manufacturing"

For i = 1 To 10
For n = LBound(SearchIn) To UBound(SearchIn)
If Rngia Is Nothing Then
Set Rngia = Cells(i, 1).Find(What:=SearchIn(n), _
LookIn:=xlValues, Lookat:=xlPart)
Else: Set Rngia = Union(Rngia, Cells(i, 1).Find(What:=SearchIn(n), _
LookIn:=xlValues, Lookat:=xlPart))
End If
Next n
Next i

Rngia.Select




"GreenInIowa" wrote:

I am using the following code to FIND "employment " and "government" and the
code is working fine.

Set rngia = Cells(i, 1).Find(What:="*employment *government",
LookIn:=xlValues, Lookat:=xlPart)

But I have others searches to do and thus, would like to use an array
variable for "What:=". Is this possible?

I tried to define "SearchIn" as array variable and used in FIND function,
but it is giving me error. I was wondering why?

Dim SearchIn As Range

SearchIn(1) = "*employment *government"
SearchIn(2) = "*employment *manufacturing"

Set rngia = Cells(i, 1).Find(What:=SearchIn(n), LookIn:=xlValues,
Lookat:=xlPart)

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Using Array variable in FIND function

JMB,

After your clarification it is now working okay! Apparently, I was not
declaring the array properly. I choose to go with your first suggestion,
though:
.....
Dim SearchIn(1 To 9) As String
SearchIn(1) = "Employment (NAICS), Government (Thousands)"
SearchIn(2) = "Employment (NAICS), Manufacturing (Thousands)"
....

Thank you.

"JMB" wrote:

You have to define SearchIn as an array, not a range. Also, SearchIn(n) will
not work as n is not defined. I think the structure you're looking for might
look something like this. I assume you have a loop set up that increments
the variable "i". If you are looping through a range and want every cell
that contains the values you're looking for, you could use the Union function
instead of Exit For (in the Else statement).

Dim SearchIn(1 To 2) As String
Dim Rngia As Range
Dim n As Long

SearchIn(1) = "*employment *government"
SearchIn(2) = "*employment *manufacturing"

For n = LBound(SearchIn) To UBound(SearchIn)
If Rngia Is Nothing Then
Set Rngia = Cells(i, 1).Find(What:=SearchIn(n), _
LookIn:=xlValues, Lookat:=xlPart)
Else: Exit For
End If
Next n
With the Union function

Dim SearchIn(1 To 2) As String
Dim Rngia As Range
Dim n As Long
Dim i As Long

On Error Resume Next

SearchIn(1) = "*employment *government"
SearchIn(2) = "*employment *manufacturing"

For i = 1 To 10
For n = LBound(SearchIn) To UBound(SearchIn)
If Rngia Is Nothing Then
Set Rngia = Cells(i, 1).Find(What:=SearchIn(n), _
LookIn:=xlValues, Lookat:=xlPart)
Else: Set Rngia = Union(Rngia, Cells(i, 1).Find(What:=SearchIn(n), _
LookIn:=xlValues, Lookat:=xlPart))
End If
Next n
Next i

Rngia.Select




"GreenInIowa" wrote:

I am using the following code to FIND "employment " and "government" and the
code is working fine.

Set rngia = Cells(i, 1).Find(What:="*employment *government",
LookIn:=xlValues, Lookat:=xlPart)

But I have others searches to do and thus, would like to use an array
variable for "What:=". Is this possible?

I tried to define "SearchIn" as array variable and used in FIND function,
but it is giving me error. I was wondering why?

Dim SearchIn As Range

SearchIn(1) = "*employment *government"
SearchIn(2) = "*employment *manufacturing"

Set rngia = Cells(i, 1).Find(What:=SearchIn(n), LookIn:=xlValues,
Lookat:=xlPart)

Thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FIND function for an array FARAZ QURESHI Excel Discussion (Misc queries) 3 January 26th 07 04:21 AM
Variable Table Array in Lookup Function matt_the_brum Excel Worksheet Functions 6 August 4th 06 05:07 PM
How to find out the size of a variable-size array ? Adrian[_7_] Excel Programming 1 July 6th 04 09:12 AM
Find size of array passed to user-defined function Cliff[_2_] Excel Programming 2 October 21st 03 02:09 AM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 07:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"