2017-02-28 57 views

回答

1

让假设你想上的值值B中柱基值。

那么你的代码应该是这样的:

Sub fillValues() 
Dim i, k As Integer 
k = Cells(1, 1).CurrentRegion.Rows.Count  'determine last row 
For i = 1 To k 
    If Cells(i, 1).Value > 0 Then 
     Cells(i, 2).Value = 0 
    End If 
Next i 
End Sub 
+0

对不起,我是新的VBA(XLS) 我怎么会使用这个代码?在Excel中 –

+0

只需打开Visual Basic中的窗口,过去,那么你应该可以运行它作为一个宏。 –

+0

谢谢您的快速支持 –

1

如果youwant值自动chenge一旦你的列中的任何地方进入的0值:B,那么您需要在您的代码Worksheet_Change事件。

注:不知道我underatand如果你想,当你更改单元格中的一个00到mekt其他细胞0

Private Sub Worksheet_Change(ByVal Target As Range) 

Application.EnableEvents = False 
If Not Intersect(Target, Columns("A:B")) Is Nothing Then ' check if a cell in Columns A:B is changed 
    If Target.Value = 0 Then '<-- if the value changed is 0 
    ' option 2 to your post 
    'If Target.Value > 0 Then '<-- if the value changed is > 0 
     Select Case Target.Column '<-- check which column modifed, A or B 
      Case 1 
       Target.Offset(, 1).Value = 0 
      Case 2 
       Target.Offset(, -1).Value = 0 
     End Select    
    End If  
End If 
Application.EnableEvents = True 

End Sub 
+0

谢谢您的快速支持 –

相关问题