簡體   English   中英

如何使用VB.NET在Excel中查找相鄰的單元格值

[英]How to find the adjacent cell value in excel using VB.NET

我被這種情況所困擾。 我閱讀了該論壇,並嘗試了多種方法來解決此問題,但沒有任何效果。

這是場景:

我正在使用vb.net自動生成excel工作表。 此工作表在A列中填充了200個數據值,在B列中填充了200個不同數據值。然后,我找到了B列及其相關地址的最大值(例如maxvalue = 2.59,地址$ B $ 89)。 現在,我需要查找相鄰單元格的值(在A列中),並在消息框中顯示該值。

任何幫助都感激不盡。

謝謝

蘇迪爾

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM