2017-05-26 117 views
0

基本上我現在有這個權利:https://i.gyazo.com/5890c00b96526f86c8bea8b5f4fe3a85.pngExcel的VB - 依賴於其他單元格設置單元格值

我需要的是這樣的:

如果小區1 = 0,則設置單元格2的值爲10和小區3爲0,如果電池1 = 1,則電池單元3的值設置爲10和電池2爲0。

我的嘗試:

If cell1 = 1 Then 
    cell2 = 10 
Else 
    ActiveCell.Offset(0, 2).Select 
    ActiveCell.Value = 10 
    cell2 = 0 
End If 

它爲小區2但不爲小區3。 (#VALUE!)

有什麼想法嗎?

+0

有一個在你上面貼的代碼沒有小區3。 – jivko

回答

0

假定活動單元格爲小區1,修改您的代碼一點,它可以作爲要求,請嘗試,讓我知道

Sub test() 
'assuming activecell as cell 1 

If ActiveCell.Value = 0 Then 'cell 1 
    ActiveCell.Offset(0, 2).Value = 10 'cell 2 
    ActiveCell.Offset(0, 4).Value = 0 'cell 3 
End If 
    If ActiveCell.Value = 1 Then 'cell 1 
    ActiveCell.Offset(0, 2).Value = 0 'cell 2 
    ActiveCell.Offset(0, 4).Value = 10 'cell 3 
End If 
End Sub 
相關問題