VBA的索引(小)等效,在循环中查找下一个实例而不是相同的实例

时间:2016-06-23 12:52:26

标签: excel vba loops indexing

Sub Random()
'if you have questions or you broke the macro, reach out to the AU DataDudes!
Dim J As Integer
Dim P As Integer
Dim V As Integer
Dim Production As Worksheet
Dim Distro As Worksheet
Dim IRowL As Integer
Dim ProwL As Integer
Dim StartRange As Range

Set Production = Worksheets("Alias Production Detail Report")
Set Distro = Worksheets("WorkList")


IRowL = Distro.Cells(Distro.Rows.Count, "A").End(xlUp).Row 'if you changed the location of the Name in the Gracie sheet change this
ProwL = Production.Cells(Production.Rows.Count, "A").End(xlUp).Row 'if you change the location of the name in the master sheet change this
Application.ScreenUpdating = False

For J = 2 To IRowL
        For P = 2 To ProwL

            If Distro.Cells(J, 1).Value = Production.Cells(P, 6).Value Then
            If Production.Cells(P, 5).Value <> Distro.Cells((J - 1), 5).Value Then

                    Production.Cells(P, 1).EntireRow.Copy
                    Distro.Cells(J, 1).Select
                    ActiveSheet.Paste
                    Exit For
            End If
            End If
        Next P
Next J
Application.ScreenUpdating = True

MsgBox ("All Done!")

对于VBA的小等价物是否采用超原始方法,但它仅适用于2的实例,

If Production.Cells(P, 5).Value <> Distro.Cells((J - 1), 5).Value 

有人可以提供关于在循环中使用small的方法/思考过程,结果可以不断地反复获取下一个实例而不是同一个实例。

0 个答案:

没有答案