2016-07-07 43 views
0

我是一個新手,自己編碼和學習者。我在一個正在研究的小型實驗項目上受到嚴重困擾。請幫助我。從給定範圍內找到一個具有特定值的單元格,並從最上面一行和第一列中找到相應的值

Base Data

這是我打算做的。 請參閱附加的圖片 - 從給定的表格中,我想找到一個具有特定值的單元格(比如0.1314)。然後,我想從最上一行和第一列中的相應單元格中查找並添加值(即-1.1 + 0.2)。

我已經嘗試使用查找,匹配和查找命令,但總是出現一些錯誤。

請建議這是什麼適當的命令提示符。任何人都可以幫助我的代碼?

感謝 SHREYA

+0

你會得到什麼錯誤?發佈你的嘗試。 – newguy

+0

'Find()'將找到你想要的值的單元格(我們稱之爲'f') - 然後你可以使用'f.Row'和'f.Column'來獲取行和列標題。發佈你的當前代碼,你會得到更多的幫助。 –

回答

0

建議就如何實現自己的目標。如果有什麼不清楚的,請在評論中告訴我。

Sub FindAndModify() 

    Dim cel As Range 
    Dim LookupValue As Double 
    Dim intRow As Integer 
    Dim intCol As Integer 
    Dim celValue As Double 

    LookupValue = "0.5" 'Define your Lookup Value here or read it from a cell 

    For Each cel In Sheet1.UsedRange 

     If cel.Value = LookupValue Then 

      intRow = cel.Row 
      intCol = cel.Column 

      celValue = cel.Value 

      celValue = celValue + Sheet1.Cells(intRow, 1).Value 
      celValue = celValue + Sheet1.Cells(1, intCol).Value 

      MsgBox "Value is " & celValue & " and address is " & cel.Address 

      'Do stuff with your values 

     End If 

    Next cel 

End Sub 
相關問題