LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 114
Default Array problem

Hi,
I'm having problems with the code below. I want to create an array
from a range. This array will hold the codes for different tasks.
Then i need to loop through a range and highlight any codes which are
ont contained in the array. I can do this if I manually fill the
array using code, but this takes too long and would need constant
adjustments. So filling the array from a range is far better for me.
When I run this code is stops on this line:

If c.Value = ValidationArray(i) Then
I get a subscript out of range error.

also how do I declare "i"? I've just used Dim i as variant for now

Hope you can help.
regards,
Matt


Sub ValidateStaffStatus()
'validates the task codes of the amended staff

Dim c As Range
Dim There As Boolean
Dim ErrCount As Integer
Dim i as variant
Dim ValidationArray() As Variant
ValidationArray() = ThisWorkbook.Sheets("All Shifts").Range
("B3:B41").Value

ThisWorkbook.Sheets("AWD").Select
ThisWorkbook.Sheets("AWD").Range("E2:L1001").Clear Formats
For Each c In Range("E2:E10")
If Not c.Value = "" Then 'the cell is not empty
If Not IsNumeric(c.Value) Then 'the cell value is not numeric
If Not c.Value = "NWD" Then 'not a non working day
'validate the status codes
There = False
For i = 0 To UBound(ValidationArray)
If c.Value = ValidationArray(i) Then
There = True
Exit For
End If
Next

If There = False Then
c.Interior.ColorIndex = 3
ErrCount = ErrCount + 1
End If
End If
End If
End If
Next c

If ErrCount = 0 Then
MsgBox "No errors have been found"
Else
MsgBox "Your data contains " & ErrCount & " error(s). These have been
highlighted for correction."
End If

End Sub
 
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
array problem natanz[_2_] Excel Programming 5 January 31st 06 04:18 PM
array problem Rbp9ad[_2_] Excel Programming 1 November 29th 05 05:29 PM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 6 November 9th 05 05:54 AM
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Excel Programming 1 November 8th 05 04:21 AM
Array-problem Tom Excel Programming 2 November 24th 03 05:59 PM


All times are GMT +1. The time now is 09:43 AM.

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"