2014-04-29 76 views
1

我想在cell("A1")中輸入一個值,然後該單元格將與A3的值相乘,新值將替換A3A1已清除。刪除另一個單元曾經使用過的單元格的值

我已經進入了下面的代碼,但它不僅整列,我希望它從20 T2適用於整列和行一路AP2所以42

Private Sub worksheet_change(ByVal target As Range) 
     If target.Column = 20 And target.Value > 0 Then 
     Dim val As Double 
     val = target.Value 
     target.Value = 0 
     Cells(target.Row, target.Column - 1).Value = val + Cells(target.Row, target.Column - 1).Value 
     End If 
    End Sub 
+0

不清晰的問題......是A3的價值改變? – whytheq

+0

是的,它是將股票輸入到Excel表格中,隨時填入空單元格,以輸入剛剛收回的股票數量。 – user3584495

+0

我已經運行程序,它給我的是我輸入的值的消息框,它不會與「A3」相乘。我真的很樂意幫助你,畢竟我只是一個大膽的人。 – user3584495

回答

0
Private Sub worksheet_change(ByVal target As Range) 
    If target.Address = "$A$1" And target.Value > 0 Then 
    Dim val As Double 
    val = target.Value 
    Range("A1").Value = 0 
    Cells(3, 1) = val * Cells(3, 1) 
    End If 
End Sub 

加入到Sheet1工作模塊:

enter image description here

似乎測試OK:

enter image description here

+0

還有一件事,我將如何將它應用於孔行我的情況「A1」到「T1」和「A3」到「T3」? – user3584495

+0

...所以如果有人想改變C1的值,那麼C3應該改變?應該很簡單 - 我們只需要使用'target.Address =「$ A $ 1」'還有'Range(「A1」)。Value = 0'。嘗試將它們分別改爲'target.row = 1'和'target.Value = 0'分別...? – whytheq

+0

你好,我仍然有一個問題,讓我的程序運行,我想它,我已經設法讓洞列工作,但我需要所有12行工作行星星在20所以「T2」和跳過列下一個是22所以「V2」...一直到「AP2」 Private Sub worksheet_change(ByVal target As Range) If target.Column = 20 And target.Value> 0 Then Dim val作爲雙 VAL = target.Value target.Value = 0 細胞(target.Row,target.Column - 1)。價值= VAL +細胞(target.Row,target.Column - 1)。價值 結束如果 End Sub – user3584495

0

你可以使用的東西像這樣:

Dim flagProgram As Boolean 
Private Sub worksheet_change(ByVal target As Range) 
Dim dblResult As Double 
If flagProgram = False Then 
    flagProgram = True 
    dblResult = Cells(1, 1) * Cells(1, 3) 
    Cells(1, 1) = "" 
    flagProgram = False 
End If 

End Sub 
0

你可以使用它。

Private Sub worksheet_change(ByVal target As Range) 

    Dim rng As Range 
    Dim db As Double 
    Set target = Range("a1") 
    If target.Value > 0 Then 
    db = target.Value * Cells(1, 3) 
    MsgBox db 
    target.Value = "" 
    End If 
End Sub 
+0

爲什麼使用'msgBox' - 使事情變得複雜 – whytheq

相關問題