Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21256

Find next not working

$
0
0
I am creating a user form that searches one excel sheet and copies a row and pastes it into another sheet. It will find the first string but will not find the next string.

Dim FindString As Date
Dim Rng As Range
Dim FirstAddress As Variant
Dim ws As Worksheet
Dim oRange As Range
Dim ExitLoop As Boolean
Dim FoundAt As Variant
Dim Rcount As Long
Dim I As Long
Dim MyArr As Variant
Set ws = Worksheets("Sheet1")
Set oRange = ws.Columns(2)

Rcount = 0

FindString = Application.InputBox("Enter Date")

MyArr = Array(FindString)

Set Rng = oRange.find(what:=MyArr(I), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

For I = LBound(MyArr) To UBound(MyArr)

If Not Rng Is Nothing Then
Application.Goto Rng, True

Range(ActiveCell, ActiveCell.Offset(0, 0)).EntireRow.Copy
Sheets(2).Activate
Range("A1").Select
ActiveSheet.Paste


Do While ExitLoop = False

Set FirstAddress = Rng
FoundAt = Rng.Address

Set Rng = oRange.FindNext(Rng)

If FirstAddress = MyArr(I) Then
Rcount = Rcount + 1

If FoundAt = FirstAddress.Address Then
Exit Do
Else
ExitLoop = True
End If
End If

Loop

Else
MsgBox "Nothing found"

End If
Next

End Sub

Viewing all articles
Browse latest Browse all 21256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>