查找下一个和上一个记录以在Userform

时间:2015-08-26 15:58:44

标签: excel vba

我有一个userform,我想在其中显示记录。但是,代码返回第一个找到的值:

Private Sub commandbutton3_click() 

Dim c As Range
Dim a As String

With Worksheets("Sheet1").Range("N:N")
Set c = .Find(What:="Pending", LookIn:=xlValues)

If Not c Is Nothing Then
   FirstAddress = c.Address

   Do
      Set c = .findnext(c)
      a = c.Offset(0, -9).Value
      Me.Control1.Value = c.Offset(0, -13)
      Me.Control2.Value = c.Offset(0, -12)
      Me.Control3.Value = c.Offset(0, -9) & " " & c.Offset(0, -8)
      Me.Control4.Value = c.Offset(0, -7)
      Me.Control5.Value = c.Offset(0, -6)
      Me.Control6.Value = Format(c.Offset(0, -10), "dd-mmm-yyyy")
      Me.Control7.Value = c.Offset(0, -5)
      Me.Control8.Value = c.Offset(0, 10)
      Me.Control9.Value = c.Offset(0, -4)
      Me.Control10.Value = c.Offset(0, -3)
      Me.Control11.Value = c.Offset(0, -2)
      Me.Control12.Value = c
      Me.Control13.Value = Format(c.Offset(0, -1), "dd-mmm-yyyy")    
      Me.Control14.Value = c.Offset(0, 1)
      Me.Control15.Value = c.Offset(0, 2)
      Me.Control16.Value = Format(c.Offset(0, 3), "dd-mmm-YYYY")
      Me.Control17.Value = c.Offset(0, 4)
      Me.Control18.Value = c.Offset(0, 6)
      Me.Control19.Value = Format(c.Offset(0, 5), "dd-mmm-yyyy")
      Me.Control20.Value = c.Offset(0, 7)
      Me.Control21.Value = c.Offset(0, 9)
      Me.Control22.Value = Format(c.Offset(0, 8), "dd-mmm-yyyy")

    Loop While Not c Is Nothing And c.Address <> FirstAddress

End If

End With

End Sub

请帮忙

0 个答案:

没有答案