Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Check if first character of string is in array

Hello.

The code below works correctly except I need it to determine if a string
begins with another string stored in an array, not contains the string
stored in the array. For example

If the data is Should return Actually Returns

112 112 112
201 115 201
115 183 115
183 183
254
390

here is the code that I have modified so far from another posting here.

Dim rng As Range, cell As Range, arrVar As Variant
Dim strAddress1 As String, rngUnion As Range
Set rng = Range("Main!c:c")
For Each arrVar In Array("1", "2")
Set cell = rng.Find(arrVar, LookIn:=xlValues, Lookat:=xlPart,
MatchCase:=True)
If Not cell Is Nothing Then
strAddress1 = cell.Address
Do
If rngUnion Is Nothing Then
Set rngUnion = cell
Else
Set rngUnion = Union(cell, rngUnion)
End If
Set cell = rng.FindNext(cell)
Loop While Not cell Is Nothing And _
cell.Address < strAddress1
End If
Next arrVar
If Not rngUnion Is Nothing Then
rngUnion.EntireRow.Copy
End If

Any help would be appreciated.

Thanks

Jonathan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Check if first character of string is in array

It should return
112 starts with 1
201 starts with 2
115 starts with 1
183 starts with 1
254 starts with 2

Maybe you should make it clearer what your criteria is.

Regards,
Tom Ogilvy


Jonathan wrote in message
news:Dskhb.1101$XS4.677@edtnps84...
Hello.

The code below works correctly except I need it to determine if a string
begins with another string stored in an array, not contains the string
stored in the array. For example

If the data is Should return Actually Returns

112 112 112
201 115 201
115 183 115
183

183
254
390

here is the code that I have modified so far from another posting here.

Dim rng As Range, cell As Range, arrVar As Variant
Dim strAddress1 As String, rngUnion As Range
Set rng = Range("Main!c:c")
For Each arrVar In Array("1", "2")
Set cell = rng.Find(arrVar, LookIn:=xlValues, Lookat:=xlPart,
MatchCase:=True)
If Not cell Is Nothing Then
strAddress1 = cell.Address
Do
If rngUnion Is Nothing Then
Set rngUnion = cell
Else
Set rngUnion = Union(cell, rngUnion)
End If
Set cell = rng.FindNext(cell)
Loop While Not cell Is Nothing And _
cell.Address < strAddress1
End If
Next arrVar
If Not rngUnion Is Nothing Then
rngUnion.EntireRow.Copy
End If

Any help would be appreciated.

Thanks

Jonathan




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Check if first character of string is in array

You are correct, the output should be what you listed. For posting purposes
I was planning on only putting one value in the array. Sorry about the
confusion.

Jonathan

"Tom Ogilvy" wrote in message
...
It should return
112 starts with 1
201 starts with 2
115 starts with 1
183 starts with 1
254 starts with 2

Maybe you should make it clearer what your criteria is.

Regards,
Tom Ogilvy


Jonathan wrote in message
news:Dskhb.1101$XS4.677@edtnps84...
Hello.

The code below works correctly except I need it to determine if a string
begins with another string stored in an array, not contains the string
stored in the array. For example

If the data is Should return Actually Returns

112 112

112
201 115

201
115 183

115
183

183
254
390

here is the code that I have modified so far from another posting here.

Dim rng As Range, cell As Range, arrVar As Variant
Dim strAddress1 As String, rngUnion As Range
Set rng = Range("Main!c:c")
For Each arrVar In Array("1", "2")
Set cell = rng.Find(arrVar, LookIn:=xlValues, Lookat:=xlPart,
MatchCase:=True)
If Not cell Is Nothing Then
strAddress1 = cell.Address
Do
If rngUnion Is Nothing Then
Set rngUnion = cell
Else
Set rngUnion = Union(cell, rngUnion)
End If
Set cell = rng.FindNext(cell)
Loop While Not cell Is Nothing And _
cell.Address < strAddress1
End If
Next arrVar
If Not rngUnion Is Nothing Then
rngUnion.EntireRow.Copy
End If

Any help would be appreciated.

Thanks

Jonathan






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Check if first character of string is in array

I would use:

Set cell = rng.Find(arrVar & "*", LookIn:=xlValues, _
Lookat:=xlWhole, MatchCase:=True)

Include a wildcard on the end of the search term. Look at xlWhole

This has worked for me in similar situations.

--
Regards,
Tom Ogilvy


"Jonathan" wrote in message
news:UwAhb.8713$XS4.7645@edtnps84...
You are correct, the output should be what you listed. For posting

purposes
I was planning on only putting one value in the array. Sorry about the
confusion.

Jonathan

"Tom Ogilvy" wrote in message
...
It should return
112 starts with 1
201 starts with 2
115 starts with 1
183 starts with 1
254 starts with 2

Maybe you should make it clearer what your criteria is.

Regards,
Tom Ogilvy


Jonathan wrote in message
news:Dskhb.1101$XS4.677@edtnps84...
Hello.

The code below works correctly except I need it to determine if a

string
begins with another string stored in an array, not contains the string
stored in the array. For example

If the data is Should return Actually

Returns

112 112

112
201 115

201
115 183

115
183

183
254
390

here is the code that I have modified so far from another posting

here.

Dim rng As Range, cell As Range, arrVar As Variant
Dim strAddress1 As String, rngUnion As Range
Set rng = Range("Main!c:c")
For Each arrVar In Array("1", "2")
Set cell = rng.Find(arrVar, LookIn:=xlValues, Lookat:=xlPart,
MatchCase:=True)
If Not cell Is Nothing Then
strAddress1 = cell.Address
Do
If rngUnion Is Nothing Then
Set rngUnion = cell
Else
Set rngUnion = Union(cell, rngUnion)
End If
Set cell = rng.FindNext(cell)
Loop While Not cell Is Nothing And _
cell.Address < strAddress1
End If
Next arrVar
If Not rngUnion Is Nothing Then
rngUnion.EntireRow.Copy
End If

Any help would be appreciated.

Thanks

Jonathan








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Check if first character of string is in array

That worked perfectly.

Thanks

Jonathan

"Tom Ogilvy" wrote in message
...
I would use:

Set cell = rng.Find(arrVar & "*", LookIn:=xlValues, _
Lookat:=xlWhole, MatchCase:=True)

Include a wildcard on the end of the search term. Look at xlWhole

This has worked for me in similar situations.

--
Regards,
Tom Ogilvy


"Jonathan" wrote in message
news:UwAhb.8713$XS4.7645@edtnps84...
You are correct, the output should be what you listed. For posting

purposes
I was planning on only putting one value in the array. Sorry about the
confusion.

Jonathan

"Tom Ogilvy" wrote in message
...
It should return
112 starts with 1
201 starts with 2
115 starts with 1
183 starts with 1
254 starts with 2

Maybe you should make it clearer what your criteria is.

Regards,
Tom Ogilvy


Jonathan wrote in message
news:Dskhb.1101$XS4.677@edtnps84...
Hello.

The code below works correctly except I need it to determine if a

string
begins with another string stored in an array, not contains the

string
stored in the array. For example

If the data is Should return Actually

Returns

112 112

112
201 115

201
115 183

115
183
183
254
390

here is the code that I have modified so far from another posting

here.

Dim rng As Range, cell As Range, arrVar As Variant
Dim strAddress1 As String, rngUnion As Range
Set rng = Range("Main!c:c")
For Each arrVar In Array("1", "2")
Set cell = rng.Find(arrVar, LookIn:=xlValues, Lookat:=xlPart,
MatchCase:=True)
If Not cell Is Nothing Then
strAddress1 = cell.Address
Do
If rngUnion Is Nothing Then
Set rngUnion = cell
Else
Set rngUnion = Union(cell, rngUnion)
End If
Set cell = rng.FindNext(cell)
Loop While Not cell Is Nothing And _
cell.Address < strAddress1
End If
Next arrVar
If Not rngUnion Is Nothing Then
rngUnion.EntireRow.Copy
End If

Any help would be appreciated.

Thanks

Jonathan












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
Check for character in string dksaluki Excel Discussion (Misc queries) 3 December 11th 07 12:53 PM
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
check if the text string start with a specific character September21 New Users to Excel 5 September 22nd 05 03:07 PM
Check if a String is inside an Array Dave Peterson[_3_] Excel Programming 3 September 3rd 03 08:41 PM
Check if a String is inside an Array Alan Beban[_3_] Excel Programming 0 September 3rd 03 07:44 PM


All times are GMT +1. The time now is 05:16 PM.

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

About Us

"It's about Microsoft Excel"