PC Review


Reply
Thread Tools Rate Thread

check if valid and size array

 
 
=?Utf-8?B?QXJuZSBIZWdlZm9ycw==?=
Guest
Posts: n/a
 
      17th Apr 2007
Hi! I have a udf that reads the contents of a certain nnumber of cells. If
the contents in these cells match the contents of any position in any of two
arrays defined by me in my code then contents of that cell is valid and can
be processed further.

My code starts like this:

Function basel(Rating As Range) As String

Dim i As Long
Dim j As Long
Dim A() As String
Dim RatingScale As Variant
Dim MdyRatingScale As Variant

RatingScale = Array("AAA", "AA+", "AA", "AA-", "A+", "A", "A-", "BBB+",
"BBB", "BBB-")
MdyRatingScale = Array("Aaa", "Aa1", "Aa2", "Aa3", "A1", "A2", "A3",
"Baa1", "Baa2", "Baa3")

The two arrays define what is ok content. I want my code to check if the
content in the cells that it is taking in as argument is ok. if it is ok the
code shall place the content into an array called A. It is important that
there are no empty places in A so it needs to de Redimmed so that it is only
as big as it needs to be. can someone help me with this please! thanks alot!!
 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      17th Apr 2007
Arne,
Depending exactly what you expect as a return value, you can amend this:

Function basel(Rating As Range) As String
Dim cell As Range

Const RatingScale As String = ",AAA,AA+,AA,AA-,A+,A,A-,BBB+,BBB,BBB-,"
Const MdyRatingScale As String = ",Aaa,Aa1,Aa2,Aa3,A1,A2,A3,Baa1,Baa2,Baa3,"

For Each cell In Rating
Debug.Print cell.Text
If InStr(1, RatingScale, "," & cell.Text & ",") = 0 Then
If InStr(1, MdyRatingScale, "," & cell.Text & ",") = 0 Then
basel = "No match: " & cell.Text
Exit Function
End If
End If
Next

basel = "All match"

End Function

Maybe someone more knowledgable in RegEx than me could come with a
Pattern....

NickHK

"Arne Hegefors" <(E-Mail Removed)> wrote in message
news:029BAA8A-D649-4485-8043-(E-Mail Removed)...
> Hi! I have a udf that reads the contents of a certain nnumber of cells. If
> the contents in these cells match the contents of any position in any of

two
> arrays defined by me in my code then contents of that cell is valid and

can
> be processed further.
>
> My code starts like this:
>
> Function basel(Rating As Range) As String
>
> Dim i As Long
> Dim j As Long
> Dim A() As String
> Dim RatingScale As Variant
> Dim MdyRatingScale As Variant
>
> RatingScale = Array("AAA", "AA+", "AA", "AA-", "A+", "A", "A-",

"BBB+",
> "BBB", "BBB-")
> MdyRatingScale = Array("Aaa", "Aa1", "Aa2", "Aa3", "A1", "A2", "A3",
> "Baa1", "Baa2", "Baa3")
>
> The two arrays define what is ok content. I want my code to check if the
> content in the cells that it is taking in as argument is ok. if it is ok

the
> code shall place the content into an array called A. It is important that
> there are no empty places in A so it needs to de Redimmed so that it is

only
> as big as it needs to be. can someone help me with this please! thanks

alot!!


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
check array size when variable = nothing yhlove@gmail.com Microsoft VB .NET 7 17th May 2007 01:44 PM
Check if valid XML doc Adrian Microsoft VB .NET 2 8th Aug 2005 05:17 PM
how to check if URL is valid? Rolf Mistelbacher Microsoft VB .NET 2 9th Nov 2004 07:22 PM
Last valid value in array bcmiller Microsoft Excel Programming 2 21st Jun 2004 09:47 AM
Array formulas are not valid in merged cells. khinester6666@yahoo.com Microsoft Excel Programming 1 17th Oct 2003 04:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:33 AM.