如何使用VB.NET在excel中找到相邻的单元格值

时间:2014-01-09 12:45:13

标签: vb.net excel-2010

我坚持这个坐姿。我阅读了论坛并尝试了许多方法来解决这个问题,但没有工作。

以下是该方案:

我正在使用vb.net自动生成excel工作表。该工作表在A列中填充200个数据值,在B列中填充200个不同的数据值。然后,我找到B列的最大值及其相关地址(例如maxvalue = 2.59,地址$ B $ 89)。我现在需要找到相邻单元格的值(在A列中)并在消息框中显示该值。

任何帮助将不胜感激。

谢谢

Sudhir

1 个答案:

答案 0 :(得分:0)

Dim xlsApp As Excel.Application = Nothing
    Dim xlsWorkBooks As Excel.Workbooks = Nothing
    Dim xlsWB As Excel.Workbook = Nothing

    Try

        xlsApp = New Excel.Application
        xlsApp.Visible = True
        xlsWorkBooks = xlsApp.Workbooks
        xlsWB = xlsWorkbooks.Open("c:\my_excel_file.xls")

        xlsWB.Range("B89").Select   'This will move the cursor to B89 cell
        Dim myValue as String = ""

        myValue = xlsWB.Activecell.Offset(0,-1).Value
                      'Offset(0,-1) means we are interested in the
                      'cell in which lies on the same row (0 for y axis)
                      'and to the left of the current one, by one cell
                      'which means -1 . If we want the cell in column D92 then 
                      'we would use Offset(3,2) 


    Catch ex As Exception

    Finally

        xlsWB.Close()
        xlsWB = Nothing
        xlsApp.Quit()
        xlsApp = Nothing

    End Try