2014-01-09 3 views
0

나는이 문제로 고생하고있다. 나는 포럼을 읽고 이것을 해결하기 위해 수많은 방법을 시도했지만 작동하지 않았다.VB.NET을 사용하여 Excel에서 인접한 셀 값을 찾는 방법

내가 vb.net을 사용하여 엑셀 워크 시트로 자동으로 생성하고 다음은

는 시나리오입니다. 이 워크 시트에는 열 A에 200 개의 데이터 값과 열 B에 200 개의 다른 데이터 값이 채워집니다. 그런 다음 연결된 주소 (예 : maxvalue = 2.59, 주소 $ B $ 89)와 함께 열 B의 최대 값을 찾습니다. 이제는 인접한 셀의 값 (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 
관련 문제