PDA

View Full Version : Copy & Paste



khalid79m
01-20-2009, 05:27 AM
I need help in writing a macro that will

on sheet1 filter on range named CHECK for Complete,

then on the filtered data cut it and paste on sheet 2 in the next avaliable row using column a to find then next available row.

Important please note on sheet1 row 1 and 2 are headers!

I have this process in placed but it involves using another sheet and mulitple filters, i need to stream line... any help would be appreciated:dunno

lucas
01-20-2009, 08:09 AM
What are you filtering for? Can you check that column for that item and cut and paste if?

khalid79m
01-20-2009, 08:33 AM
Each row of data from 3 to 65536 potenital may hold data about a Customer Call. So 1row = 1call... I want to filter on the range "CHECK" for "Complete" and the complete results need to be cut and pasted elsewhere.. does that make sense?

lucas
01-20-2009, 08:41 AM
So what column would you be looking for the word "complete"

khalid79m
01-20-2009, 11:05 AM
The column is AV3 & lastrow , (it saved as a named range called CHECK).

I hope that helps.

georgiboy
01-20-2009, 11:35 AM
Something like this...

Sub Macro()
Dim rCell As Range

For Each rCell In Sheet1.Range("CHECK").Cells

If UCase(rCell.Value) = "COMPLETE" Then
rCell.EntireRow.Cut Sheet2.Range("A" & Sheet2.Range("A" & Rows.Count).End(xlUp).Row + 1)
End If

Next

End Sub

Edit: You may want to swap "A" for "AV" so it populates sheet2 fully

Hope this helps

lucas
01-20-2009, 11:37 AM
This should work....it worked for me:
Option Explicit
Sub Main()

Dim i As Long

For i = TargetRow(ActiveSheet, 1) - 1 To 2 Step -1
If ActiveSheet.Cells(i, 48).Value = "complete" Then
ActiveSheet.Rows(i).Copy Sheets("Sheet2").Cells(TargetRow(Sheets("Sheet2"), 1), 1)
ActiveSheet.Rows(i).Delete
End If
Next i

End Sub

Function TargetRow(ByRef ws As Worksheet, ByVal col As Long) As Long
'returns index of first empty row from bottom of sheet
'requires worksheet object and column index
TargetRow = ws.Cells(Rows.Count, col).End(xlUp).Row
If IsEmpty(ws.Cells(TargetRow, col)) Then
'in this case the column is empty
'change targetrow to 2 to move the rows starting on the second row
TargetRow = 3
Else
TargetRow = TargetRow + 1
End If
End Function

khalid79m
01-21-2009, 02:42 AM
Hi Gorgieboy,

what do you mean by

Edit: You may want to swap "A" for "AV" so it populates sheet2 fully?

Your code works fine by the way , exactly what I need as it uses the named range.

Thanks for the help lucas really appreciate it.