2014-01-09 80 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 
相關問題