我希望它从上到下开始搜索第一列,然后是第二个等等。更改从左到右,从上到下,到上下,从左到右的搜索流程
在“每个”部分我想改变流动
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
'that is the Matrix I want to Change the search flow in'
For Each cell In Range("a2:aap15")
If cell.Interior.ColorIndex = 6 Then
If cell.Value = "" Then
cell.Value = ActiveCell.Value
Exit For
End If
End If
Next
Next
Next
End Sub
我必须写这句话,因为stackoverlow不会让我发布,直到它认为我没有做主要的代码了。
新建议(还是同样的问题):
Private Sub CommandButton1_Click()
Dim i As Integer
Dim j As Integer
'NEW'
Dim cell As Range, column As Range
For j = 2 To 2
For i = 21 To 21
If Cells(i - 1, j).Value = 0 Then
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
End If
'NEW'
For Each column In Range("a2:aap15").Columns
For Each cell In column.Cells
If cell.Interior.ColorIndex = 6 Then
If cell.Value = "" Then
cell.Value = ActiveCell.Value
Exit For
End If
End If
Next
Next
Next
next
End Sub
你真的有第一行中的所有东西(甚至是单个值)? .AutoFilter由于第一行空白而与您的示例数据搞砸了。 – Jeeped
不,我的第一行是空的。为什么? – Julian
您想使用'a2:aap15',但.AutoFilter需要'标题'行,第1行是空白。行1中任何单元格中的单个值都可以解决此问题。 – Jeeped