我的代码将矩阵1中的单元格中的文本复制到符合Matrix 2中的条件的所有单元格中。但是,我希望它仅将其复制到第一个单元格中在Matrix 2中满足我的批评,然后停下来。仅选择符合条件的范围中的第一个单元格
Private Sub CommandButton1_Click()
Dim i As Integer
Dim j As Integer
For j = 2 To 2
For i = 21 To 21
If Cells(i, j).Value > 0 Then
Cells(i, j).Value = Cells(i, j).Value - 1
Cells(i, j).Offset(0, -1).Select
End If
'as it says - for EACH - so it copies in aLL the cells'
'I can't Change the range though, cause there will come a Loop eventually'
For Each cell In Range("a1:aap15")
If cell.Interior.ColorIndex = 6 Then
If cell.Value = "" Then
cell.Value = ActiveCell.Value
End If
End If
Next
Next
Next
End Sub
为什么你有第二个循环? '对于我= 21到21'?目的是什么?(或第一个?) –
我会将b21的值减小到0,然后我会继续b22等等。我还没有到那个部分,所以我忽略了这个复杂因素,并且让它变得更加容易,直到我找出了我已经拥有的这些程序。 – Julian