2014-01-09 146 views
0

我被这个问题困住了。我阅读论坛,并尝试了许多方法来解决这个问题,但没有正常工作。如何使用VB.NET在excel中查找相邻单元格值

下面是这种情况:

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

任何帮助将不胜感激。

感谢

苏德赫

+0

我们能看出你试过,但没有工作的代码? – Ahmad

回答

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 
相关问题