+ Reply to Thread
Results 1 to 9 of 9

Need to Search from Bottom to Top

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-08-2006
    Posts
    203

    Need to Search from Bottom to Top

    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

  2. #2
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    You can build you own find function!
    Best regards,

    Ray

  3. #3
    Forum Contributor
    Join Date
    08-08-2006
    Posts
    203
    Quote Originally Posted by raypayette
    You can build you own find function!
    I didnt mean my code as in I wrote it all myself. Most of the code in my sheets are adapted from questions I ask on this forum.

    Perhaps a few keywords to get me headed in the right direction.

  4. #4
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    I suggest that this is a good time to learn VBA, so perhaps you could buy a book on it such as Microsoft's Excel 2003 Step by Step.

  5. #5
    Forum Contributor
    Join Date
    08-08-2006
    Posts
    203
    So what I asked about search from bottom to top is possible?

  6. #6
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    Yes if you build your own function!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1