Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default read and check cells in loop

Hi! I have problem with a piece of code that I dont understand. It is udf.
It works like this: it takes three cells as argument (although you dont see
that in the code). I then check the contents of those three cells to see if
they match two arrays that you can see in my code. If the content matches the
contents of one of the arrays I redim another array and places a number in
that array. It is imperative that the dimension of that array (A) equals the
number of cells with OK content. This works sometimes but if I have empty
cells that are taken in as argument in the beginning (eg in Column A) then it
does not work. Can someone please help me with this piece of code?

Function basel(Rating As Range) As String

Dim i As Long
Dim j As Long
Dim k 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")

i = 1 'räknare för kolumner
j = 1 'räknare för ratingbetyg
k = 0
For i = 1 To Rating.Columns.Count 'kollar varje kolumn för sig
For j = 1 To UBound(RatingScale) 'kollar varje OK rating
If (Rating(i) = RatingScale(j) Or Rating(i) = MdyRatingScale(j))
Then
k = k + 1
ReDim Preserve A(k) 'dimensionera om A
' MsgBox k
A(i) = j 'de får samma sifferbetyg som i ratingens placering
i arrayen
End If
Next j
Next i

€¦€¦.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default read and check cells in loop

Hi, in my opinion, within the loop, the first check you should perform is, to
verify if a cell is empty, if so, then go to the next iteration in the loop.

"Arne Hegefors" wrote:

Hi! I have problem with a piece of code that I dont understand. It is udf.
It works like this: it takes three cells as argument (although you dont see
that in the code). I then check the contents of those three cells to see if
they match two arrays that you can see in my code. If the content matches the
contents of one of the arrays I redim another array and places a number in
that array. It is imperative that the dimension of that array (A) equals the
number of cells with OK content. This works sometimes but if I have empty
cells that are taken in as argument in the beginning (eg in Column A) then it
does not work. Can someone please help me with this piece of code?

Function basel(Rating As Range) As String

Dim i As Long
Dim j As Long
Dim k 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")

i = 1 'räknare för kolumner
j = 1 'räknare för ratingbetyg
k = 0
For i = 1 To Rating.Columns.Count 'kollar varje kolumn för sig
For j = 1 To UBound(RatingScale) 'kollar varje OK rating
If (Rating(i) = RatingScale(j) Or Rating(i) = MdyRatingScale(j))
Then
k = k + 1
ReDim Preserve A(k) 'dimensionera om A
' MsgBox k
A(i) = j 'de får samma sifferbetyg som i ratingens placering
i arrayen
End If
Next j
Next i

€¦€¦.


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
loop to check cells for numbers between 2 number range Olamide Excel Programming 7 February 28th 07 07:01 PM
Do Loop for Error check Stephen Excel Programming 8 July 20th 06 01:26 PM
check blocks in loop sybmathics Excel Programming 4 June 3rd 06 04:35 PM
having probelms getting my loop to terminate on an array value read from an empty cell mizcrab Excel Programming 3 November 30th 05 02:54 AM
Create a Loop to check cells between workbooks No Name Excel Programming 0 September 16th 04 04:35 PM


All times are GMT +1. The time now is 10:15 AM.

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"