Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
First thing you need to do is get your own logic sorted out!!! You say
you want to 'flag' the last column with "wrong", but state the last col as "G" of a 12 col array. (Doesn't make sense) Here's how I might approach this task... Sub Flag_NegativeValues() Dim n&, rngData As Range, lLastCol&, lLastRow& Set rngData = ActiveSheet.UsedRange With rngData lLastCol = .Columns.Count: lLastRow = .Rows.Count End With 'rngData With Application For n = 1 To lLastRow If .CountIf(.Index(rngData, n, 0), "<0") 0 Then Cells(n, lLastCol + 1) = "wrong" End If Next 'n End With 'Application End Sub ...where I write directly to the sheet rather than rebuild an output array that has to be written later. If you prefer to build an output array then... Sub Flag_NegativeValues2() Dim vData, n&, lRows&, lCols&, rng As Range Set rng = ActiveSheet.UsedRange: vData = rng lRows = UBound(vData): lCols = UBound(vData, 2) ReDim Preserve vData(1 To lRows, 1 To lCols + 1) With Application For n = LBound(vData) To UBound(vData) If .CountIf(.Index(rng, n, 0), "<0") 0 Then vData(n, UBound(vData, 2)) = "wrong" End If Next 'n ActiveSheet.UsedRange.Resize(UBound(vData), UBound(vData, 2)) = vData End With 'Application End Sub -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Web Query Results to an Array | Excel Programming | |||
ARRAY QUERY | Excel Programming | |||
Array data in SQL Query? | Excel Programming | |||
Web Query & Array Questions! | Excel Programming | |||
Query for data in an array | Excel Programming |