11-11-21 11:14 AM
Dim strDir as String = direction.Trim().Substring(0,1).ToUpper()
Dim excel as Object = GetInstance(handle)
Dim dirn as Integer = 0
Select Case strDir
Case "U"
dirn = -4162 ' Excel.XlDirection.xlToUp
Case "D"
dirn = -4121 ' Excel.XlDirection.xlToDown
Case "L"
dirn = -4159 ' Excel.XlDirection.xlToLeft
Case "R"
dirn = -4161 ' Excel.XlDirection.xlToRight
Case Else
Throw New ArgumentException("Invalid Direction: " & strDir)
End Select
Dim cell as Object = excel.ActiveCell
While True
Dim nextCell as Object = GetNextCell(cell, strDir)
If cell.Address = nextCell.Address Then
cellref = ""
Return
ElseIf cstr(nextCell.Value) = value Then ' We've found our blank
cellref = nextCell.Address(False,False)
Return
End If
cell = nextCell
End While
11-11-21 02:49 PM
11-11-21 09:01 PM
If you want to indicate all the lines having any specific value in a collection, in that case I have modified the code in such a way that you need to provide the following inputs & outputs:Dim strDir as String = direction.Trim().Substring(0,1).ToUpper()
Dim excel as Object = GetInstance(handle)
Dim dirn as Integer = 0
Select Case strDir
Case "U"
dirn = -4162 ' Excel.XlDirection.xlToUp
Case "D"
dirn = -4121 ' Excel.XlDirection.xlToDown
Case "L"
dirn = -4159 ' Excel.XlDirection.xlToLeft
Case "R"
dirn = -4161 ' Excel.XlDirection.xlToRight
Case Else
Throw New ArgumentException("Invalid Direction: " & strDir)
End Select
Dim totalRows As Integer = GetWorksheet(handle,workbookname,worksheetname).Cells.Find("*", , , , , 2).Row
Dim lineCount As Integer = 1
excel.ActiveSheet.Range(cellref,cellref).Activate()
Dim cell as Object = excel.ActiveCell
Dim temp As New DataTable
temp.Columns.Add("lineNo", GetType(Integer))
For i As Integer = 0 To totalRows
Dim nextCell as Object = GetNextCell(cell, strDir)
If nextCell.Value = value Then ' We've found our value
temp.Rows.Add(lineCount)
End If
cell = nextCell
lineCount +=1
Next
lines=temp
12-11-21 09:45 AM
12-11-21 09:48 AM
12-11-21 10:20 AM
14-11-21 03:27 PM