I have a UserForm that searches through data starting at A1 and going down. A separate UserForm is what pastes the data starting with A1 and going down. Ive found that when my user submits bad data, they just re-submit new data. The problem is that when the code below searches through the data, it finds the bad data first. Is there a way to change this code so it searches starting with A60000 and goes up?
Here is my code
Private Sub CommandButton1_Click()
Dim RngStart
Dim RngEnd
Dim NewFindName
Dim NewFindNameEnd
Dim CopyRng As Range
Dim ws As Worksheet
Dim Wsdes As Worksheet
Dim StartRow
Dim EndRow
Dim FoundCell
Dim LastRow
Set ws = Sheets("sheet1")
Set Wsdes = Sheets("sheet2")
Set Wsbol = Sheets("BOL1")
NewFindName = cboloctran1.Value
'NewFindName = InputBox("Enter name to find: ")
NewFindNameEnd = NewFindName & "end"
ws.Activate
'Range("E1").Value = NewFindName
'Range("E2").Value = NewFindNameEnd
With Range("A:A") ' setrange to match index search column
Set FoundCell = .Cells.Find(What:=NewFindName, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
StartRow = (FoundCell.Row) ' row number of foundcell
RngStart = ("A" & StartRow)
' Range("d1").Value = RngStart
With Range("A:A") ' setrange to match index search column
Set FoundCell = .Cells.Find(What:=NewFindNameEnd, _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
EndRow = (FoundCell.Row) ' row number of foundcell
RngEnd = ("C" & EndRow)
' Range("d2").Value = RngEnd
Wsdes.Cells.ClearContents
Set CopyRng = ws.Range(RngStart & ":" & RngEnd)
CopyRng.Copy
Wsdes.Select
Wsdes.Range("A1").PasteSpecial Paste:=xlPasteValues
ws.Activate
ws.Range("A1").Select
ActiveWorkbook.Sheets("BOL1").Activate
Range("I1").Select
Unload Me
End Sub
Bookmarks