View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
CYaYa CYaYa is offline
external usenet poster
 
Posts: 6
Default macro to copy rows that contain a cell with a certain number

Good morning,

I have recorded the macro below and need to expand it's capabilities.
It's a mixture of recording key strokes and inserting code I found on this
site. So I know there are some things in the macro that probably do nothing.
With that said the macro performs what I need it to as it is recorded now.
However I would like to have it do the following after what it is already
doing:

Go back to the sheet named "Current unapplied" and if cell L = 0 have it
copy the entire row and paste it in the sheet named "unapplied Copy" in the
next available blank row. Every week the information in the two sheets are
variable.

I tried to use the same code that deletes the rows in "Unapplied copy"
where cell L = 0 but I get an error message. So any help that can be provided
will be greatly appreciated. Thanks.

Chad

Sub Macro3()
'
' Macro3 Macro
'

'
Sheets("Current Unapplied").Select
Range("J2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=CONCATENATE(RC[-9],RC[-8],RC[-7],RC[-6],RC[-5],RC[-4],RC[-3])"
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
Selection.AutoFill Destination:=Range("J2:J703"), Type:=xlFillDefault
Range("J2:J703").Select
ActiveWindow.ScrollRow = 679
ActiveWindow.ScrollRow = 544
ActiveWindow.ScrollRow = 272
ActiveWindow.ScrollRow = 1
Range("K2").Select
ActiveCell.FormulaR1C1 = "1"
Range("K3").Select
ActiveCell.FormulaR1C1 = "2"
Range("K4").Select
ActiveCell.FormulaR1C1 = "3"
Range("K2:K4").Select
Selection.AutoFill Destination:=Range("K2:K703")
Range("K2:K703").Select
Sheets("Unapplied Copy").Select
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
Range("J2").Select
ActiveCell.FormulaR1C1 = _
"=CONCATENATE(RC[-9],RC[-8],RC[-7],RC[-6],RC[-5],RC[-4],RC[-3])"
ActiveWindow.ScrollColumn = 7
ActiveWindow.ScrollColumn = 8
Selection.AutoFill Destination:=Range("J2:J722"), Type:=xlFillDefault
Range("J2:J722").Select
ActiveWindow.ScrollRow = 661
ActiveWindow.ScrollRow = 397
ActiveWindow.ScrollRow = 265
ActiveWindow.ScrollRow = 133
ActiveWindow.ScrollRow = 1
Range("K2").Select
ActiveCell.FormulaR1C1 = "1"
Range("K3").Select
ActiveCell.FormulaR1C1 = "2"
Range("K4").Select
ActiveCell.FormulaR1C1 = "3"
Range("K2:K4").Select
Selection.AutoFill Destination:=Range("K2:K722")
Range("K2:K722").Select
Range("L2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-2],'Current Unapplied'!RC[-2]:RC[-1],2,FALSE)"
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(VLOOKUP(RC[-2],'Current
Unapplied'!R2C10:R5000C11,2,FALSE)),d,(VLOOKUP(RC[-2],'Current
Unapplied'!R2C10:R5000C11,2,FALSE)))"
Range("L2").Select
Selection.AutoFill Destination:=Range("L2:L722")
Range("L2:L722").Select
Range("L2").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(VLOOKUP(RC[-2],'Current
Unapplied'!R2C10:R5000C11,2,FALSE)),_delete,(VLOOK UP(RC[-2],'Current
Unapplied'!R2C10:R5000C11,2,FALSE)))"
Range("L2").Select
Selection.AutoFill Destination:=Range("L2:L722")
Range("L2:L722").Select
Range("L2").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(VLOOKUP(RC[-2],'Current
Unapplied'!R2C10:R5000C11,2,FALSE)),0,(VLOOKUP(RC[-2],'Current
Unapplied'!R2C10:R5000C11,2,FALSE)))"
Range("L2").Select
Selection.AutoFill Destination:=Range("L2:L722")
Range("L2:L722").Select
Range("L2").Select
Sheets("Current Unapplied").Select
Range("L2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-2],'Unapplied Copy'!RC[-2]:RC[-1],2,FALSE)"
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(VLOOKUP(RC[-2],'Unapplied
Copy'!R2C10:R5000C11,2,FALSE)),0,(VLOOKUP(RC[-2],'Unapplied
Copy'!R2C10:R5000C11,2,FALSE)))"
Range("L2").Select
Selection.AutoFill Destination:=Range("L2:L703")
Range("L2:L703").Select
Range("L2").Select
Sheets("Unapplied Copy").Select
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Range("A2").Select
Dim MyRange, MyRange1 As Range
lastrow = Cells(Rows.Count, "l").End(xlUp).Row
Set MyRange = Sheets("Unapplied Copy").Range("l1:l" & lastrow)
For Each c In MyRange
If UCase(c.Value) = "0" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
Sheets("Current Unapplied").Select
Sheets("Unapplied Copy").Activate
mlastrow = Cells(Rows.Count, "A").End(xlUp).Row
Cells(mlastrow + 1, "A").Activate

End Sub