Results 1 to 3 of 3

Thread: finding and moving a range of data using .

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2013
    Posts
    17

    finding and moving a range of data using .

    Hello! I am trying to write a code that selects a range of data and moves it to a new sheet. I want it to select beginning when column 6=1 and 7=18 and go until 6=10 and 7=-35
    I tried the code before, but it doesnt move the right range... Am I using the .find wrong? Any help appreciated. Thank you!

    Code:
     Dim lRow1 As Long, lRow2 As Long
        Dim lStart As Long, lEnd As Long
         
        With Columns(6)
            lRow1 = .Find(What:="1", After:=Cells(1, 6), LookIn:=xlFormulas _
            , LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).row
             
            lRow2 = .Find(What:="10", After:=Cells(1, 6), LookIn:=xlFormulas _
            , LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).row
        End With
        
     With Columns(7)
         lRow1 = .Find(What:="18", After:=Cells(1, 7), LookIn:=xlFormulas _
            , LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).row
             
            lRow2 = .Find(What:="-35", After:=Cells(1, 7), LookIn:=xlFormulas _
            , LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).row
    End With
      
     Sheets.Add
     ActiveSheet.Name = "FreezeControl"
     Sheets("control").Select
     rows(lRow1 & ":" & lRow2).Select
     Selection.Copy
     Sheets("Freezecontrol").Select
     Range("A1").Select
     ActiveSheet.Paste

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: finding and moving a range of data using .

    Thread moved to the 'Office Development/VBA' forum... note that while it certainly isn't made clear, the "VB Editor" in Office programs is actually VBA rather than VB, so the 'VB6' forum is not really apt

  3. #3
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: finding and moving a range of data using .

    Not sure how your data is arranged, but you do realize that your "with columns(6)" FIND is getting over-written by your "with columns(7)" FIND, right (since they both assign to lRow1 and lRow2)?

    I'm assuming that's not your intent?

Posting Permissions

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



Click Here to Expand Forum to Full Width