macro question

VQCHEESE

Board Regular
Joined
Aug 28, 2006
Messages
161
I have a macro that sorts a column, and copies and pastes data based on that sort to a new sheet within same workbook. But this task is repeated and when the macro copies it over writes the data from the first time the macro runs. below is the code from my macro the sheet i am copying from is Todo and the sheet i am copying to is completed. also i would need to be able to have the macro select a new set of data to be copied over based on the sorting as well.

Columns("A:H").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$H$39").AutoFilter Field:=5, Criteria1:="<>"
Range("A4:H7").Select
Selection.Cut
Sheets("Completed").Select
Range("A4").Select
ActiveSheet.Paste
Sheets("Todo").Select
ActiveSheet.Range("$A$1:$H$39").AutoFilter Field:=5
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try this on a copy of your data as it is untested.
Code:
Columns("A:H").AutoFilter
ActiveSheet.Range("$A$1:$H$39").AutoFilter Field:=5, Criteria1:="<>"
Range("A4:H7").Cut Destination:=Sheets("Completed").Range.Cells(Rows.Count, "A").End(xlUp)
Sheets("Todo").Select
ActiveSheet.Range("$A$1:$H$39").AutoFilter Field:=5
 
Upvote 0
ok i have alot more done on this but am still missing a big piece.

When i sort by the criteria(which is weahter there is an x in the cell. it will sort fine and only show which ones have the x. but the cells may not always be in order. right now i have an x in cell 4, 8, 9, 10, as you can see from below its only taking rows 8:10, how would i make that take 4 also. But then if a row 12 has data in it but no x i dont want that to copy, how would i take those rows out.




ActiveSheet.Range("$A$1:$H$39").AutoFilter Field:=5, Criteria1:="<>"
Rows("8:10").Select
 
Upvote 0
Do you want copy all rows that contain an x? Which column would the x be in? Which sheet is this data in, and which sheet do you want it to go to?
 
Upvote 0
Do you want copy all rows that contain an x? Which column would the x be in? Which sheet is this data in, and which sheet do you want it to go to?

Yes all rows that have the x,
x is in column E
Todo is the sheet i am copying from
Completed is the sheet i am copying to.
 
Upvote 0
Try this
Code:
Dim LR As Long, i As Long
Sheets("Todo").Select
LR = Range("E" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    If Range("E" & i).Value = "x" Then Rows(i).Copy Destination:=Sheets("Completed").Range.Cells(Rows.Count, "A").End(xlUp)
Next i
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top