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
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
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?