Hi Friends, I got error message While Writing Macro Code For Highlight The Color Red , If the Testing the Products ,Data Value is >= 120 And <=140 that is From 120 To 140 Using For …Next Loop, Can you Find The Error in My Macro Code, Where I Made Mistake ?
That is I want To High Light The Cell in Red Color which Values are Between 120 To 140
Here is The Code…
Sub Highlight_TheCell_UsingArray()
Dim Doc As Object, Sheet As Object, Range As Object, Cell As Object, Cursor As Object
Dim i As Integer, j As Integer, Data() As Variant
Doc = ThisComponent : Sheet = Doc.Sheets.getByName("Sheet1")
Cell = Sheet.getCellRangeByName("A1")
Cursor = Sheet.CreateCursorByRange(Cell)
' Cursor.collapseToCurrentRegion()
Cursor.gotoEndOfUsedArea(True)
Doc.CurrentController.Select(Cursor)
Range = Cursor.getRangeAddress()
Print Range.StartColumn & "," & Range.StartRow & "," & Range.EndColumn & "," & Range.EndRow
Data = Cursor.getDataArray() ' Range(0, 0, 4, 10)
For i = LBound(Data()) To UBound(Data())
For j = LBound(Data(0)) To UBound(Data(0))
If Data(i)(j) >= 120 And Data(i, j) <= 140 Then
Cell.CellBackColor = RGB(255,0,0)
End If
Next j
Next i
End Sub
Here, Is the Calc Data File
Test_101.ods (9.1 KB)