Excel VB-设置依赖于其他单元格的单元格值

Excel VB-设置依赖于其他单元格的单元格值,excel,vb.net,vba,Excel,Vb.net,Vba,基本上我现在有这个: 我需要的是: 如果单元格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 它适用于cell2,但不适用于cell3。(#价值!) 有什么想法吗

基本上我现在有这个:

我需要的是:

如果单元格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
它适用于cell2,但不适用于cell3。(#价值!)


有什么想法吗?

假设活动单元格为单元格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

上面粘贴的代码中没有cell3。