Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default How do I handle #Value in VBA?

Hi Everyone,

In VBA, I'm searching for a substring in a cell using worksheet function FIND.
If FIND does not find the substring it returns a #Value (instead of 0 which
is what I want)

I'm not sure how to handle this.

here's my code...
....
With ActiveWorkbook.Worksheets("Sheet1")
Do While Not IsEmpty(Cells(i, 1))
If (Application.WorksheetFunction.Find("xyz", Cells(i, 7))
< 0) Then
Worksheets("Sheet2").Cells(j, 1) =
Worksheets("Sheet1").Cells(i, 1)
i = i + 1
j = j + 1
End If
Loop
End With

If "xyz" does not exist, the code crashes. =( instead of just continuing

Thanks As Always!!! Kurt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default How do I handle #Value in VBA?

If you just need to know whether or not a string matches a simple pattern,
you can use the LIKE operator:
If Cells(i, 7) LIKE "*xyz*" then
Here i use the wildcard character '*' meaning 'any number of characters'
therefore the expression means "cell contains the substring xyz or XYZ"

From the online help, other wildcard chars:
? -- Any single character.
*-- Zero or more characters.
#-- Any single digit (0€“9).
[charlist] -- Any single character in charlist.
[!charlist] -- Any single character not in charlist

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"kurt" wrote:

Hi Everyone,

In VBA, I'm searching for a substring in a cell using worksheet function FIND.
If FIND does not find the substring it returns a #Value (instead of 0 which
is what I want)

I'm not sure how to handle this.

here's my code...
...
With ActiveWorkbook.Worksheets("Sheet1")
Do While Not IsEmpty(Cells(i, 1))
If (Application.WorksheetFunction.Find("xyz", Cells(i, 7))
< 0) Then
Worksheets("Sheet2").Cells(j, 1) =
Worksheets("Sheet1").Cells(i, 1)
i = i + 1
j = j + 1
End If
Loop
End With

If "xyz" does not exist, the code crashes. =( instead of just continuing

Thanks As Always!!! Kurt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default How do I handle #Value in VBA?

Let me know how this goes:

i = 1
j = 1
Do While Not IsEmpty(Cells(i, 1))
If InStr(Cells(i, 7), "xyz") Then
Worksheets("Sheet2").Cells(j, 1) = Worksheets("Sheet1").Cells(i, 1)
i = i + 1
j = j + 1
End If
Loop


"sebastienm" wrote:

If you just need to know whether or not a string matches a simple pattern,
you can use the LIKE operator:
If Cells(i, 7) LIKE "*xyz*" then
Here i use the wildcard character '*' meaning 'any number of characters'
therefore the expression means "cell contains the substring xyz or XYZ"

From the online help, other wildcard chars:
? -- Any single character.
*-- Zero or more characters.
#-- Any single digit (0€“9).
[charlist] -- Any single character in charlist.
[!charlist] -- Any single character not in charlist

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"kurt" wrote:

Hi Everyone,

In VBA, I'm searching for a substring in a cell using worksheet function FIND.
If FIND does not find the substring it returns a #Value (instead of 0 which
is what I want)

I'm not sure how to handle this.

here's my code...
...
With ActiveWorkbook.Worksheets("Sheet1")
Do While Not IsEmpty(Cells(i, 1))
If (Application.WorksheetFunction.Find("xyz", Cells(i, 7))
< 0) Then
Worksheets("Sheet2").Cells(j, 1) =
Worksheets("Sheet1").Cells(i, 1)
i = i + 1
j = j + 1
End If
Loop
End With

If "xyz" does not exist, the code crashes. =( instead of just continuing

Thanks As Always!!! Kurt

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default How do I handle #Value in VBA?

this was the one!

thanks! =)

Kurt

"Access101" wrote:

Let me know how this goes:

i = 1
j = 1
Do While Not IsEmpty(Cells(i, 1))
If InStr(Cells(i, 7), "xyz") Then
Worksheets("Sheet2").Cells(j, 1) = Worksheets("Sheet1").Cells(i, 1)
i = i + 1
j = j + 1
End If
Loop


"sebastienm" wrote:

If you just need to know whether or not a string matches a simple pattern,
you can use the LIKE operator:
If Cells(i, 7) LIKE "*xyz*" then
Here i use the wildcard character '*' meaning 'any number of characters'
therefore the expression means "cell contains the substring xyz or XYZ"

From the online help, other wildcard chars:
? -- Any single character.
*-- Zero or more characters.
#-- Any single digit (0€“9).
[charlist] -- Any single character in charlist.
[!charlist] -- Any single character not in charlist

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"kurt" wrote:

Hi Everyone,

In VBA, I'm searching for a substring in a cell using worksheet function FIND.
If FIND does not find the substring it returns a #Value (instead of 0 which
is what I want)

I'm not sure how to handle this.

here's my code...
...
With ActiveWorkbook.Worksheets("Sheet1")
Do While Not IsEmpty(Cells(i, 1))
If (Application.WorksheetFunction.Find("xyz", Cells(i, 7))
< 0) Then
Worksheets("Sheet2").Cells(j, 1) =
Worksheets("Sheet1").Cells(i, 1)
i = i + 1
j = j + 1
End If
Loop
End With

If "xyz" does not exist, the code crashes. =( instead of just continuing

Thanks As Always!!! Kurt

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
How to handle something like this DK Excel Discussion (Misc queries) 0 May 19th 09 11:40 PM
what is "fill handle". i don't see any fill handle in my excel Neelakanta New Users to Excel 32 June 18th 08 12:48 PM
Fill handle turned into a move handle Northwoods Excel Discussion (Misc queries) 1 March 2nd 07 03:40 PM
Am I trying to do something that Excel cannot handle? KG Excel Discussion (Misc queries) 1 February 20th 05 01:40 PM
Not sure how to handle this hotherps[_139_] Excel Programming 2 August 29th 04 06:27 PM


All times are GMT +1. The time now is 11:30 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"