View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default Macro for Moving rows

Make a copy of your workbook to test this on first just to be sure. If the
sheet names as shown on the tabs are not dump-hr and blm10, change the code
to use the actual sheet names as shown on the tabs.

Copy the routine below and put it into a regular code module. To do that,
open your workbook and use [Alt]+[F11] to get into the VB Editor. Choose
Insert | Module from the menu of the VB Editor. Paste the code into the
module and close the VB Editor.

It will copy all rows on the dump-hr sheet with any form of 'blm' in column
N (as blm, BLM, Blm, etc) and the value 10 in column P. It will stop copying
when it comes to an empty cell in column N. If the blm10 sheet is empty it
will start putting the copied information on row 2, otherwise it will start
at the first row on that sheet with an empty cell in column N.

Sub MoveRowsToBLM10()

Dim srcRange As Range
Dim dstRange As Range
Const srcSheetName = "dump-hr" ' change if needed
Const dstSheetName = "blm10" ' change if needed
Dim Roffset As Long
Dim dstRow As Long

Worksheets(srcSheetName).Select
Range("N1").Select
Do Until IsEmpty(ActiveCell.Offset(Roffset, 0))
'case is important we make sure of match to BLM,
'and if P# is text vs number then
'enclose 10 in quotes as = "10" below
If UCase(Trim(ActiveCell.Offset(Roffset, 0))) = "BLM" And _
ActiveCell.Offset(Roffset, 2) = 10 Then
Set srcRange = Worksheets(srcSheetName). _
Rows(Roffset + 1 & ":" & Roffset + 1)
'find available row on dest sheet
dstRow = Worksheets(dstSheetName).Range("N" _
& Rows.Count).End(xlUp).Row + 1
Set dstRange = Worksheets(dstSheetName). _
Rows(dstRow & ":" & dstRow)
dstRange.Value = srcRange.Value
End If
Roffset = Roffset + 1
Loop
'empty out the dump-hr sheet
ActiveSheet.Cells.Clear
Set srcRange = Nothing
Set dstRange = Nothing
End Sub


"M.A.Tyler" wrote:

I need a macro to move rows from one sheet to another based on the row
meeting two criteria.

Sheet1!("dump-hr") contains large quantity of data (pasted in) I would like
to move rows that meet specific criteria in columns "N" and "P" to
sheet2!("blm10"). The criteria for column "N" is "blm" and for column "P"
it's "10". Hopefully the rows would be moved to the next available row on
Sheet2!("blm"), then Sheet2!("blm") would need to be saved.
Sheet1!("dump-hr") would then be deleted of data, and more data pasted in to
start the process over.

Is this possible?

Thanks in advance!

M.A.Tyler.